Skip to content

Commit

Permalink
fix: use gix-command for interactive edit
Browse files Browse the repository at this point in the history
gix-command emulate's git's behavior a little more closely w.r.t. when to execute the
editor with a shell and split arguments.

For example, using a shell script as the editor like this now works:

   GIT_EDITOR='printf "log: %s\n" "$1" >some.log && nvim -- "$1"' stg edit

This may also help with running the editor in a Windows environment.

Ref: #407
  • Loading branch information
jpgrayson committed Jan 30, 2024
1 parent fefdc48 commit 048f182
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
19 changes: 19 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ ctrlc = "3.4"
encoding_rs = "0.8"
flate2 = "1"
gix = { version = "0.58", default-features = false, features = ["revision"] }
gix-command = "0.3"
indexmap = "2.1"
is-terminal = "0.4"
nom = { version = "7", default_features = false, features = ["std"] }
Expand Down
24 changes: 8 additions & 16 deletions src/patch/edit/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,22 +113,14 @@ pub(crate) fn call_editor<P: AsRef<Path>>(
}

fn run_editor<P: AsRef<Path>>(editor: &OsStr, path: P) -> Result<std::process::ExitStatus> {
let mut subcommand = OsString::new();
subcommand.push(editor);
subcommand.push(" ");
subcommand.push(path.as_ref().as_os_str());

let shell = if cfg!(target_os = "windows") {
"sh"
} else {
"/bin/sh"
};

let mut child = std::process::Command::new(shell)
.arg("-c")
.arg(subcommand)
.spawn()
.with_context(|| format!("running editor: {}", editor.to_string_lossy()))?;
let mut child = std::process::Command::from(
gix_command::prepare(editor)
.arg(path.as_ref())
.with_shell_allow_argument_splitting()
.stdout(std::process::Stdio::inherit()),
)
.spawn()
.with_context(|| format!("running editor: {}", editor.to_string_lossy()))?;

child
.wait()
Expand Down

0 comments on commit 048f182

Please sign in to comment.