Skip to content

Commit df38e33

Browse files
hippusDeusData
authored andcommitted
fix(windows): use cmd.exe-compatible syntax for git-log history pass
The git-history popen command used `cd '%s' && git log ... 2>/dev/null`, which fails on Windows cmd.exe: single quotes are not recognized and /dev/null is not a valid path, producing "The filename, directory name, or volume label syntax is incorrect" at the git-history step of a full index. Switch to `git -C "%s" log ... 2>NUL` (POSIX: 2>/dev/null), which is valid on both cmd.exe and POSIX shells. Double-quoting the path is safe because cbm_validate_shell_arg already rejects ", $, backtick, backslash and the other active metacharacters before the command is built. Distilled from #325 onto current main (preserves the :%%ct commit-time field added since the PR branch). Closes #324.
1 parent 926eb7f commit df38e33

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

src/pipeline/pass_githistory.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,19 @@ static int parse_git_log(const char *repo_path, commit_t **out, int *out_count)
225225
}
226226

227227
char cmd[CBM_SZ_1K];
228+
#ifdef _WIN32
229+
/* cmd.exe does not recognize single quotes, and '/dev/null' is a POSIX path. */
230+
const char *null_dev = "NUL";
231+
#else
232+
const char *null_dev = "/dev/null";
233+
#endif
234+
/* git -C "<path>" works on both cmd.exe and POSIX shells. Double quotes are
235+
* safe here because cbm_validate_shell_arg (above) rejects ", $, `, \ and the
236+
* other shell metacharacters that would otherwise be active inside them. */
228237
snprintf(cmd, sizeof(cmd),
229-
"cd '%s' && git log --name-only --pretty=format:COMMIT:%%H:%%ct "
230-
"--since='1 year ago' --max-count=10000 2>/dev/null",
231-
repo_path);
238+
"git -C \"%s\" log --name-only --pretty=format:COMMIT:%%H:%%ct "
239+
"--since=\"1 year ago\" --max-count=10000 2>%s",
240+
repo_path, null_dev);
232241

233242
FILE *fp = cbm_popen(cmd, "r");
234243
if (!fp) {

0 commit comments

Comments
 (0)