Skip to content

Commit b094467

Browse files
committed
Clean up Git info a bit
Remove an extraneous newline, and pass `--git-dir` to `git` to ensure that out-of-repo builds don't accidentally pick up a parent repo's info.
1 parent 67720c2 commit b094467

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

preproc/src/git.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ pub struct Commit {
2020
impl Commit {
2121
pub fn rev_parse(what: &str) -> Result<Self, Error> {
2222
let output = Command::new("git")
23-
.args(["show", "-s", "--format=%H%x00%h%x00%ci", what])
23+
.args([
24+
"--git-dir=.git",
25+
"show",
26+
"-s",
27+
"--format=%H%x00%h%x00%ci",
28+
what,
29+
])
2430
.stderr(Stdio::inherit())
2531
.stdin(Stdio::null())
2632
.output()
@@ -31,15 +37,18 @@ impl Commit {
3137
output.status
3238
)));
3339
}
34-
let info = String::from_utf8(output.stdout).expect("Commit info is not valid UTF-8??");
40+
let mut info = String::from_utf8(output.stdout).expect("Commit info is not valid UTF-8??");
41+
let trimmed_len = info.trim_end().len();
42+
info.truncate(trimmed_len);
3543

3644
let first_split = info
3745
.find('\0')
3846
.expect("Failed to split hash and short hash");
3947
let second_split = info[first_split + 1..]
4048
.find('\0')
4149
.expect("Failed to split short hash and timestamp")
42-
+ first_split;
50+
+ first_split
51+
+ 1;
4352

4453
Ok(Self {
4554
info,

0 commit comments

Comments
 (0)