Skip to content

Commit 45d1be9

Browse files
committed
refactor
- carog fmt
1 parent acde47d commit 45d1be9

File tree

2 files changed

+31
-24
lines changed

2 files changed

+31
-24
lines changed

src/command/release/git.rs

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,40 +20,43 @@ pub(in crate::command::release_impl) fn commit_changes<'a>(
2020
// `git commit -am` only stages tracked files, so we need to explicitly add new ones.
2121
if !changelog_paths.is_empty() {
2222
let index = ctx.repo.open_index()?;
23-
let worktree = ctx.repo.workdir().expect("this is a worktree repository");
24-
23+
let workdir = ctx.repo.workdir().context("Can only work in non-bare repositories")?;
24+
2525
let untracked_paths: Vec<_> = changelog_paths
2626
.iter()
2727
.filter(|path| {
2828
// Convert absolute path to worktree-relative path with forward slashes
29-
path.as_ref()
30-
.strip_prefix(worktree)
31-
.ok()
32-
.map(|relative_path| {
33-
let relative_path_unix =
34-
gix::path::to_unix_separators(gix::path::into_bstr(relative_path));
35-
// Check if the path is NOT tracked in the git index
36-
index.entry_by_path(relative_path_unix.as_bstr()).is_none()
37-
})
38-
.unwrap_or(false)
29+
path.as_ref().strip_prefix(workdir).ok().is_some_and(|relative_path| {
30+
let relative_path_unix = gix::path::to_unix_separators(gix::path::into_bstr(relative_path));
31+
// Check if the path is NOT tracked in the git index
32+
index.entry_by_path(relative_path_unix.as_bstr()).is_none()
33+
})
3934
})
4035
.collect();
4136

4237
if !untracked_paths.is_empty() {
43-
let mut add_cmd = Command::new("git");
44-
add_cmd.arg("add").arg("--");
38+
let mut git_add = Command::new(gix::path::env::exe_invocation());
39+
git_add.args(["add", "--"]);
4540
for path in &untracked_paths {
46-
add_cmd.arg(path.as_ref());
41+
git_add.arg(path.as_ref());
4742
}
48-
log::trace!("{} run {:?}", will(dry_run), add_cmd);
49-
if !dry_run && !add_cmd.status()?.success() {
50-
let paths: Vec<_> = untracked_paths.iter().map(|p| p.as_ref().display().to_string()).collect();
51-
bail!("Failed to add new changelog files to git: {}", paths.join(", "));
43+
log::trace!("{} run {:?}", will(dry_run), git_add);
44+
let output = git_add.output()?;
45+
if !dry_run && !output.status.success() {
46+
let paths: Vec<_> = untracked_paths
47+
.iter()
48+
.map(|p| p.as_ref().display().to_string())
49+
.collect();
50+
bail!(
51+
"Failed to add new changelog files to git: {}: {err}",
52+
paths.join(", "),
53+
err = output.stderr.to_str_lossy()
54+
);
5255
}
5356
}
5457
}
5558

56-
let mut cmd = Command::new("git");
59+
let mut cmd = Command::new(gix::path::env::exe_invocation());
5760
cmd.arg("commit").arg("-am").arg(message.as_ref());
5861
if empty_commit_possible {
5962
cmd.arg("--allow-empty");
@@ -134,7 +137,7 @@ pub fn push_tags_and_head(
134137
return Ok(());
135138
}
136139

137-
let mut cmd = Command::new("git");
140+
let mut cmd = Command::new(gix::path::env::exe_invocation());
138141
cmd.arg("push")
139142
.arg({
140143
let remote = repo

src/git/mod.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub fn change_since_last_release(package: &Package, ctx: &crate::Context) -> any
7171
}
7272

7373
pub fn assure_clean_working_tree() -> anyhow::Result<()> {
74-
let tracked_changed = !Command::new("git")
74+
let tracked_changed = !Command::new(gix::path::env::exe_invocation())
7575
.arg("diff")
7676
.arg("HEAD")
7777
.arg("--exit-code")
@@ -82,7 +82,7 @@ pub fn assure_clean_working_tree() -> anyhow::Result<()> {
8282
bail!("Detected working tree changes. Please commit beforehand as otherwise these would be committed as part of manifest changes, or use --allow-dirty to force it.")
8383
}
8484

85-
let untracked = Command::new("git")
85+
let untracked = Command::new(gix::path::env::exe_invocation())
8686
.arg("ls-files")
8787
.arg("--exclude-standard")
8888
.arg("--others")
@@ -104,7 +104,11 @@ pub fn remote_url(repo: &gix::Repository) -> anyhow::Result<Option<gix::Url>> {
104104
}
105105

106106
pub fn author() -> anyhow::Result<gix::actor::Signature> {
107-
let stdout = Command::new("git").arg("var").arg("GIT_AUTHOR_IDENT").output()?.stdout;
107+
let stdout = Command::new(gix::path::env::exe_invocation())
108+
.arg("var")
109+
.arg("GIT_AUTHOR_IDENT")
110+
.output()?
111+
.stdout;
108112
Ok(gix::actor::SignatureRef::from_bytes::<()>(&stdout)
109113
.ok()
110114
.ok_or_else(|| anyhow!("Could not parse author from GIT_AUTHOR_IDENT='{}'", stdout.as_bstr()))?

0 commit comments

Comments
 (0)