3 # This post-checkout hook is meant to be installed in msysGit's root repository.
6 # Windows does not allow deleting or overwriting files that are in use.
7 # Concretely, it does not allow msysGit's shell to call Git to update
8 # msys-1.0.dll, because the shell still uses it.
11 # Directly after a checkout (as is the case when this hook is called),
12 # some files that should have been changed (i.e. that are in the output
13 # of 'git diff --name-only $old..$new') are marked modified, i.e. the
14 # command 'git diff-files --quiet -- $files' fails.
17 # We copy a fresh /bin/sh.exe and /bin/msys-1.0.dll into a temporary
18 # directory, add a script to that directory that will add the PATH back
19 # so we can use the Git commands (which are unaffected by the issue, as
20 # they are neither MSys programs nor are they tracked), and then fixes
23 # Finally, we add a shortcut on the desktop so that it is easy for the
24 # user to start after closing all msysGit windows.
31 test "$3" != 1 && exit
32 test "$1" = "$2" && exit
33 MODIFIED
="$(cd / && git diff --ignore-submodules --name-only -z "$1".."$2" |
34 xargs -0r git ls-files --modified)"
35 test -z "$MODIFIED" && exit
36 cd /share
/msysGit ||
exit 0 # called from tmproot
38 mkdir
-p tmproot
/bin tmproot
/etc
&&
39 echo "$MODIFIED" > tmproot
/etc
/modifiedFiles
&&
40 make create-shortcut.exe
> /dev
/null
&&
41 cp /bin
/{sh.exe
,msys-1.0.dll
,git.exe
,cat.exe
,rm.exe
,xargs.exe
} \
42 /mingw
/bin
/{libcurl-4.dll
,libiconv2.dll
} tmproot
/bin
/ &&
43 cat > tmproot
/etc
/profile
<< \EOF
&&
45 cd "$(pwd -W)"/..
/..
/..
/..
47 # add original msysGit PATH
48 export PATH
=/bin
:"$(pwd)/bin:$(pwd)/mingw/bin"
51 echo "<Press Enter to close this window>" >&2
62 # Try to update files marked 'modified'
63 test -s /etc
/modifiedFiles
&& {
64 echo "Trying to finish checkout" >&2
65 cat /etc
/modifiedFiles |
66 xargs git checkout
-- ||
67 die
"Please close _all_ msysGit instances and run this shortcut again"
68 test -z "$(cat /etc/modifiedFiles |
69 xargs git diff --ignore-submodules --name-only)" ||
70 die
"At least one file could not be updated; is msysGit still running?"
73 echo "Everything up-to-date"
74 test -f /etc
/linkfile
&& rm -f "$(cat /etc/linkfile)"
77 echo "$USERPROFILE/Desktop/finish-checkout.lnk" > tmproot
/etc
/linkfile
&&
78 .
/create-shortcut
--work-dir "$(cd tmproot/bin && pwd -W)" \
79 --icon-file "$(cd ../resources && pwd -W)/msysgitlogo.ico" \
80 --arguments "--login -i" \
81 "$(pwd -W)"/tmproot
/bin
/sh.exe \
82 "$(cat tmproot/etc/linkfile)" &&
88 You appear to have modified files after switching branches. As Windows has
89 problems updating files that are in use, the most likely reason is that a
90 .dll or a .exe file needs to be updated, but that was refused due to a process
93 A shortcut 'finish-checkout' was created on your desktop to help you: quit
94 all msysGit programs, launch that shortcut, and all should be fixed.
96 die
"Could not set up temporary MSys root"