Skip to content

Commit 30643c3

Browse files
committed
git: _really_ allow running in bare repositories
When I authored 176113f (git: allow operating on bare repositories, 2023-10-01), I obviously tested only with absolute `workDir` values. Let's make it work with relative ones, too, by avoiding to override the working directory _in addition_ to specifying `--git-dir=<path>`. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent a52831f commit 30643c3

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lib/git.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ function trimTrailingNewline(str: string): string {
3737
* @throws {Error} if the command fails
3838
*/
3939
export function git(args: string[], options?: IGitOptions): Promise<string> {
40+
let workDir = (options && options.workDir) || ".";
4041
// allow the command to run in a bare repository
41-
if (options?.workDir?.endsWith(".git")) args = [`--git-dir=${options.workDir}`, ...args];
42-
43-
const workDir = (options && options.workDir) || ".";
42+
if (options?.workDir?.endsWith(".git")) {
43+
args = [`--git-dir=${options.workDir}`, ...args];
44+
workDir = ".";
45+
}
4446
if (options && options.trace) {
4547
process.stderr.write(`Called 'git ${args.join(" ")}' in '${workDir}':\n${new Error().stack}\n`);
4648
}

0 commit comments

Comments
 (0)