Skip to content

Commit 048f182

Browse files
committed
fix: use gix-command for interactive edit
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
1 parent fefdc48 commit 048f182

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

Cargo.lock

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ ctrlc = "3.4"
3535
encoding_rs = "0.8"
3636
flate2 = "1"
3737
gix = { version = "0.58", default-features = false, features = ["revision"] }
38+
gix-command = "0.3"
3839
indexmap = "2.1"
3940
is-terminal = "0.4"
4041
nom = { version = "7", default_features = false, features = ["std"] }

src/patch/edit/interactive.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -113,22 +113,14 @@ pub(crate) fn call_editor<P: AsRef<Path>>(
113113
}
114114

115115
fn run_editor<P: AsRef<Path>>(editor: &OsStr, path: P) -> Result<std::process::ExitStatus> {
116-
let mut subcommand = OsString::new();
117-
subcommand.push(editor);
118-
subcommand.push(" ");
119-
subcommand.push(path.as_ref().as_os_str());
120-
121-
let shell = if cfg!(target_os = "windows") {
122-
"sh"
123-
} else {
124-
"/bin/sh"
125-
};
126-
127-
let mut child = std::process::Command::new(shell)
128-
.arg("-c")
129-
.arg(subcommand)
130-
.spawn()
131-
.with_context(|| format!("running editor: {}", editor.to_string_lossy()))?;
116+
let mut child = std::process::Command::from(
117+
gix_command::prepare(editor)
118+
.arg(path.as_ref())
119+
.with_shell_allow_argument_splitting()
120+
.stdout(std::process::Stdio::inherit()),
121+
)
122+
.spawn()
123+
.with_context(|| format!("running editor: {}", editor.to_string_lossy()))?;
132124

133125
child
134126
.wait()

0 commit comments

Comments
 (0)