Prevent command prompt from opening when running git blame on windows (#10747)
Release Notes: - Fixed issue reported in discord where the git blame feature would open command prompt windows
This commit is contained in:
parent
d4922eb10b
commit
dd7eced2b6
4 changed files with 26 additions and 4 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -4327,6 +4327,7 @@ dependencies = [
|
||||||
"time",
|
"time",
|
||||||
"unindent",
|
"unindent",
|
||||||
"url",
|
"url",
|
||||||
|
"windows 0.53.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -24,6 +24,7 @@ text.workspace = true
|
||||||
time.workspace = true
|
time.workspace = true
|
||||||
url.workspace = true
|
url.workspace = true
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
|
windows.workspace = true
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
unindent.workspace = true
|
unindent.workspace = true
|
||||||
|
|
|
@ -14,6 +14,9 @@ use time::OffsetDateTime;
|
||||||
use time::UtcOffset;
|
use time::UtcOffset;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
use std::os::windows::process::CommandExt;
|
||||||
|
|
||||||
pub use git2 as libgit;
|
pub use git2 as libgit;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
|
@ -76,7 +79,9 @@ fn run_git_blame(
|
||||||
path: &Path,
|
path: &Path,
|
||||||
contents: &Rope,
|
contents: &Rope,
|
||||||
) -> Result<String> {
|
) -> Result<String> {
|
||||||
let child = Command::new(git_binary)
|
let mut child = Command::new(git_binary);
|
||||||
|
|
||||||
|
child
|
||||||
.current_dir(working_directory)
|
.current_dir(working_directory)
|
||||||
.arg("blame")
|
.arg("blame")
|
||||||
.arg("--incremental")
|
.arg("--incremental")
|
||||||
|
@ -85,7 +90,12 @@ fn run_git_blame(
|
||||||
.arg(path.as_os_str())
|
.arg(path.as_os_str())
|
||||||
.stdin(Stdio::piped())
|
.stdin(Stdio::piped())
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.stderr(Stdio::piped())
|
.stderr(Stdio::piped());
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
child.creation_flags(windows::Win32::System::Threading::CREATE_NO_WINDOW.0);
|
||||||
|
|
||||||
|
let child = child
|
||||||
.spawn()
|
.spawn()
|
||||||
.map_err(|e| anyhow!("Failed to start git blame process: {}", e))?;
|
.map_err(|e| anyhow!("Failed to start git blame process: {}", e))?;
|
||||||
|
|
||||||
|
|
|
@ -4,15 +4,25 @@ use collections::HashMap;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
use std::os::windows::process::CommandExt;
|
||||||
|
|
||||||
pub fn get_messages(working_directory: &Path, shas: &[Oid]) -> Result<HashMap<Oid, String>> {
|
pub fn get_messages(working_directory: &Path, shas: &[Oid]) -> Result<HashMap<Oid, String>> {
|
||||||
const MARKER: &'static str = "<MARKER>";
|
const MARKER: &'static str = "<MARKER>";
|
||||||
|
|
||||||
let output = Command::new("git")
|
let mut command = Command::new("git");
|
||||||
|
|
||||||
|
command
|
||||||
.current_dir(working_directory)
|
.current_dir(working_directory)
|
||||||
.arg("show")
|
.arg("show")
|
||||||
.arg("-s")
|
.arg("-s")
|
||||||
.arg(format!("--format=%B{}", MARKER))
|
.arg(format!("--format=%B{}", MARKER))
|
||||||
.args(shas.iter().map(ToString::to_string))
|
.args(shas.iter().map(ToString::to_string));
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
command.creation_flags(windows::Win32::System::Threading::CREATE_NO_WINDOW.0);
|
||||||
|
|
||||||
|
let output = command
|
||||||
.output()
|
.output()
|
||||||
.map_err(|e| anyhow!("Failed to start git blame process: {}", e))?;
|
.map_err(|e| anyhow!("Failed to start git blame process: {}", e))?;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue