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 rev-parse --show-cdup) &&
34 git diff --ignore-submodules --name-only -z "$1".."$2" |
35 xargs -0r git ls-files --modified)"
36 test -z "$MODIFIED" && exit
37 cd /share
/msysGit ||
exit 0 # called from tmproot
39 mkdir
-p tmproot
/bin tmproot
/etc
&&
40 echo "$MODIFIED" > tmproot
/etc
/modifiedFiles
&&
41 make create-shortcut.exe
> /dev
/null
&&
42 cp /bin
/{sh.exe
,msys-1.0.dll
,git.exe
,cat.exe
,rm.exe
,xargs.exe
} \
43 /mingw
/bin
/{libcurl-4.dll
,libiconv2.dll
} tmproot
/bin
/ &&
44 cat > tmproot
/etc
/profile
<< \EOF
&&
46 cd "$(pwd -W)"/..
/..
/..
/..
48 # add original msysGit PATH
49 export PATH
=/bin
:"$(pwd)/bin:$(pwd)/mingw/bin"
52 echo "<Press Enter to close this window>" >&2
63 # Try to update files marked 'modified'
64 test -s /etc
/modifiedFiles
&& {
65 echo "Trying to finish checkout" >&2
66 cat /etc
/modifiedFiles |
68 xargs -0r git checkout
-- ||
69 die
"Please close _all_ msysGit instances and run this shortcut again"
70 test -z "$(cat /etc/modifiedFiles |
72 xargs -0r git diff --ignore-submodules --name-only)" ||
73 die
"At least one file could not be updated; is msysGit still running?"
76 echo "Everything up-to-date"
77 test -f /etc
/linkfile
&& rm -f "$(cat /etc/linkfile)"
80 echo "$USERPROFILE/Desktop/finish-checkout.lnk" > tmproot
/etc
/linkfile
&&
82 arguments
="--login -i" &&
83 if test -n "$COMMONPROGRAMW6432"
85 arguments
="//c $command $arguments" &&
86 command="$WINDIR"\\SysWOW64
\\cmd.exe
&& echo "$arguments"
88 .
/create-shortcut
--work-dir "$(cd tmproot/bin && pwd -W)" \
89 --icon-file "$(cd ../resources && pwd -W)/msysgitlogo.ico" \
90 --arguments "$arguments" \
92 "$(cat tmproot/etc/linkfile)" &&
98 You appear to have modified files after switching branches. As Windows has
99 problems updating files that are in use, the most likely reason is that a
100 .dll or a .exe file needs to be updated, but that was refused due to a process
103 A shortcut 'finish-checkout' was created on your desktop to help you: quit
104 all msysGit programs, launch that shortcut, and all should be fixed.
106 die
"Could not set up temporary MSys root"