mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 12:53:13 +00:00
Fix build in non-colocated jj workspaces
This commit is contained in:
parent
c1b460525c
commit
0153579a4c
1 changed files with 28 additions and 9 deletions
37
build.rs
37
build.rs
|
@ -317,16 +317,35 @@ fn get_version(src_dir: &Path) -> String {
|
||||||
// So we read the SHA ourselves.
|
// So we read the SHA ourselves.
|
||||||
fn get_git_hash() -> Result<String, Box<dyn std::error::Error>> {
|
fn get_git_hash() -> Result<String, Box<dyn std::error::Error>> {
|
||||||
let gitdir = Path::new(env!("CARGO_MANIFEST_DIR")).join(".git");
|
let gitdir = Path::new(env!("CARGO_MANIFEST_DIR")).join(".git");
|
||||||
|
let jjdir = Path::new(env!("CARGO_MANIFEST_DIR")).join(".jj");
|
||||||
|
let commit_id = if gitdir.exists() {
|
||||||
|
// .git/HEAD contains ref: refs/heads/branch
|
||||||
|
let headpath = gitdir.join("HEAD");
|
||||||
|
let headstr = read_to_string(headpath)?;
|
||||||
|
let headref = headstr.split(' ').collect::<Vec<_>>()[1].trim();
|
||||||
|
|
||||||
// .git/HEAD contains ref: refs/heads/branch
|
// .git/refs/heads/branch contains the SHA
|
||||||
let headpath = gitdir.join("HEAD");
|
let refpath = gitdir.join(headref);
|
||||||
let headstr = read_to_string(headpath)?;
|
// Shorten to 9 characters (what git describe does currently)
|
||||||
let headref = headstr.split(' ').collect::<Vec<_>>()[1].trim();
|
read_to_string(refpath)?
|
||||||
|
} else if jjdir.exists() {
|
||||||
// .git/refs/heads/branch contains the SHA
|
let output = Command::new("jj")
|
||||||
let refpath = gitdir.join(headref);
|
.args([
|
||||||
// Shorten to 9 characters (what git describe does currently)
|
"log",
|
||||||
let refstr = &read_to_string(refpath)?[0..9];
|
"--revisions",
|
||||||
|
"@",
|
||||||
|
"--no-graph",
|
||||||
|
"--ignore-working-copy",
|
||||||
|
"--template",
|
||||||
|
"commit_id",
|
||||||
|
])
|
||||||
|
.output()
|
||||||
|
.unwrap();
|
||||||
|
String::from_utf8_lossy(&output.stdout).to_string()
|
||||||
|
} else {
|
||||||
|
return Err("did not find either of .git or .jj".into());
|
||||||
|
};
|
||||||
|
let refstr = &commit_id[0..9];
|
||||||
let refstr = refstr.trim();
|
let refstr = refstr.trim();
|
||||||
|
|
||||||
let version = env!("CARGO_PKG_VERSION").to_owned();
|
let version = env!("CARGO_PKG_VERSION").to_owned();
|
||||||
|
|
Loading…
Reference in a new issue