help.c: Fix detection of custom merge strategy on cygwin
commitb8a9733377a648483958bf5472158f7c01641420
authorRamsay Jones <ramsay@ramsay1.demon.co.uk>
Thu, 16 Jun 2011 20:22:16 +0000 (16 21:22 +0100)
committerJunio C Hamano <gitster@pobox.com>
Thu, 16 Jun 2011 22:02:31 +0000 (16 15:02 -0700)
treed541bc3b741bdce14279bbd8959886a20ed1d5c3
parent2c162b56f370f5c33e6a945e6922d598006c5ec4
help.c: Fix detection of custom merge strategy on cygwin

Test t7606-merge-custom.sh fails on cygwin when git-merge fails
with an "Could not find merge strategy 'theirs'" error, despite
the test correctly preparing an (executable) git-merge-theirs
script.

The cause of the failure is the mis-detection of the executable
status of the script, by the is_executable() function, while the
load_command_list() function is searching the path for additional
merge strategy programs.

Note that the l/stat() "functions" on cygwin are somewhat
schizophrenic (see commits adbc0b67faee6b and 7974843), and
their behaviour depends on the timing of various git setup and
config function calls. In particular, until the "git_dir" has
been set (have_git_dir() returns true), the real cygwin (POSIX
emulating) l/stat() functions are called. Once "git_dir" has
been set, the "native Win32 API" implementations of l/stat()
may, or may not, be called depending on the setting of the
core.filemode and core.ignorecygwinfstricks config variables.

We also note that, since commit c869753, core.filemode is forced
to false, even on NTFS, by git-init and git-clone. A user (or a
test) can, of course, reset core.filemode to true explicitly if
the filesystem supports it (and he doesn't use any problematic
windows software). The test-suite currently runs all tests on
cygwin with core.filemode set to false.

Given the above, we see that the built-in merge strategies are
correctly detected as executable, since they are checked for
before "git_dir" is set, whereas all custom merge strategies are
not, since they are checked for after "git_dir" is set.

In order to fix the mis-detection problem, we change the code in
is_executable() to re-use the conditional WIN32 code section,
which actually looks at the content of the file to determine if
the file is executable. On cygwin we also make the additional
code conditional on the executable bit of the file mode returned
by the initial stat() call. (only the real cygwin function would
set the executable bit in the file mode.)

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
help.c