Implement editor calling
This commit is contained in:
parent
cc035525ec
commit
4b281dddc9
2 changed files with 14 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
||||||
use toml::Value;
|
use toml::Value;
|
||||||
|
|
||||||
use libimagerror::into::IntoError;
|
use libimagerror::into::IntoError;
|
||||||
|
use libimagutil::edit::edit_in_tmpfile_with_command;
|
||||||
|
|
||||||
use vcs::git::error::GitHookErrorKind as GHEK;
|
use vcs::git::error::GitHookErrorKind as GHEK;
|
||||||
use vcs::git::error::MapErrInto;
|
use vcs::git::error::MapErrInto;
|
||||||
|
@ -8,6 +9,8 @@ use vcs::git::result::Result;
|
||||||
|
|
||||||
use vcs::git::action::StoreAction;
|
use vcs::git::action::StoreAction;
|
||||||
|
|
||||||
|
use git2::Repository;
|
||||||
|
|
||||||
pub fn commit_interactive(config: &Value) -> bool {
|
pub fn commit_interactive(config: &Value) -> bool {
|
||||||
match config.lookup("commit.interactive") {
|
match config.lookup("commit.interactive") {
|
||||||
Some(&Value::Boolean(b)) => b,
|
Some(&Value::Boolean(b)) => b,
|
||||||
|
@ -70,7 +73,16 @@ pub fn commit_message(repo: &Repository, config: &Value, action: StoreAction) ->
|
||||||
|
|
||||||
if commit_interactive(config) {
|
if commit_interactive(config) {
|
||||||
if commit_with_editor(config) {
|
if commit_with_editor(config) {
|
||||||
unimplemented!()
|
repo.config()
|
||||||
|
.map_err_into(GHEK::GitConfigFetchError)
|
||||||
|
.and_then(|c| c.get_string("core.editor").map_err_into(GHEK::GitConfigEditorFetchError))
|
||||||
|
.map_err_into(GHEK::ConfigError)
|
||||||
|
.map(Command::new)
|
||||||
|
.and_then(|cmd| {
|
||||||
|
let mut s = String::from(commit_template());
|
||||||
|
edit_in_tmpfile_with_command(cmd, &mut s).map(|_| s)
|
||||||
|
.map_err_into(GHEK::EditorError)
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
Ok(ask_string("Commit Message", None, false, false, None, "> "))
|
Ok(ask_string("Commit Message", None, false, false, None, "> "))
|
||||||
}
|
}
|
||||||
|
|
|
@ -167,7 +167,7 @@ impl StoreIdAccessor for UpdateHook {
|
||||||
.map_into_hook_error()
|
.map_into_hook_error()
|
||||||
);
|
);
|
||||||
|
|
||||||
let message = try!(commit_message(cfg, StoreAction::Update)
|
let message = try!(commit_message(&repo, cfg, StoreAction::Update)
|
||||||
.map_dbg_err_str("Failed to get commit message"));
|
.map_dbg_err_str("Failed to get commit message"));
|
||||||
|
|
||||||
try!(repo.commit(Some("HEAD"), &signature, &signature, &message, &tree, &parents)
|
try!(repo.commit(Some("HEAD"), &signature, &signature, &message, &tree, &parents)
|
||||||
|
|
Loading…
Reference in a new issue