Skip to content

Commit f46b4dc

Browse files
authored
run-command: refine Git LFS check on Windows 7 (#5059)
In commit 46d14a6 of PR #5042 the `wait_or_whine()` function in `run-command.c` was revised to [call](https://github.com/git-for-windows/git/blob/b105301ef9107c8c2980a24eca89a2992a1c074b/run-command.c#L571) a new function in the case where an executable fails to run, to check whether this was caused by a Git LFS binary compiled with a version of the Go language that no longer supports Windows 7. This change was made to address the issue reported in #4996. The new function, `win32_warn_about_git_lfs_on_windows7()`, [performs](https://github.com/git-for-windows/git/blob/b105301ef9107c8c2980a24eca89a2992a1c074b/compat/win32/path-utils.c#L226-L232) several initial checks to test whether the failed executable returned the exit code `0x0b00` and is named `git-lfs`, and whether we are running Windows 7 or not. Only if all these conditions are met does it then proceed to try to extract the Go language version from the binary file and check whether it is 1.21.0 or higher. However, these initial checks may not cover all possible use and failure cases. First, when running in Git Bash (in a Windows 7 SP1 virtual machine), the exit code seen from a recent Git LFS executable was `0x02`, so we also want to check for that value as well as `0x0b00`. Second, the name of the executable may not always be entirely lowercase, since it is possible to invoke Git LFS through Git by running, for example, `git LFS ls-files` (at least, on Windows, and with a case-insensitive filesystem). We therefore need to ignore case when checking the executable's name. And third, the name of the executable may not have a trailing space character, so we also need to check for the case where the name in `argv0` is simply `git-lfs`. With these changes, we can more reliably detect a failure of the Git LFS executable in a wider range of circumstances.
2 parents b105301 + ca7b9f1 commit f46b4dc

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

compat/win32/path-utils.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,18 @@ void win32_warn_about_git_lfs_on_windows7(int exit_code, const char *argv0)
221221
* Git LFS v3.5.1 fails with an Access Violation on Windows 7; That
222222
* would usually show up as an exit code 0xc0000005. For some reason
223223
* (probably because at this point, we no longer have the _original_
224-
* HANDLE that was returned by `CreateProcess()`) we get 0xb00 instead.
224+
* HANDLE that was returned by `CreateProcess()`) we observe other
225+
* values like 0xb00 and 0x2 instead. Since the exact exit code
226+
* seems to be inconsistent, we check for a non-zero exit status.
225227
*/
226-
if (exit_code != 0x0b00)
228+
if (exit_code == 0)
227229
return;
228230
if (GetVersion() >> 16 > 7601)
229231
return; /* Warn only on Windows 7 or older */
230-
if (!starts_with(argv0, "git-lfs ") ||
231-
!(git_lfs = locate_in_PATH("git-lfs")))
232+
if (!istarts_with(argv0, "git-lfs ") &&
233+
strcasecmp(argv0, "git-lfs"))
234+
return;
235+
if (!(git_lfs = locate_in_PATH("git-lfs")))
232236
return;
233237
if (get_go_version(git_lfs, buffer, sizeof(buffer)) > 0 &&
234238
skip_prefix(buffer, "go", &p) &&

0 commit comments

Comments
 (0)