Skip to content

Commit

Permalink
fix(branch): rev-parse in bare repo (#55)
Browse files Browse the repository at this point in the history
Running git rev-parse in a bare repository would cause better-branch to fail with cryptic errors. This uses the cwd as an alternative when git root can't be found.
  • Loading branch information
Everduin94 authored Dec 14, 2023
1 parent 3472b40 commit 4332e94
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,19 @@ export function infer_type_from_branch(types: string[]): string {
return found ?? "";
}

/*
rev-parse will fail in a --bare repository root
*/
export function get_git_root(): string {
return execSync("git rev-parse --show-toplevel").toString().trim();
let path = ".";
try {
path = execSync("git rev-parse --show-toplevel").toString().trim();
} catch (err) {
p.log.warn(
"Could not find git root. If in a --bare repository, ignore this warning."
);
}
return path;
}

export function get_default_config_path(): string {
Expand Down

0 comments on commit 4332e94

Please sign in to comment.