checkout: automerge local changes while switching branches.
When switching branches, if the working tree has a local modification at paths that are different between current and new branches, we refused the operation saying "cannot merge." This attempts to do an automerge for such paths. This is still experimental. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Jan 11, 2006 at 23:07 UTC
19205acfc29b6d39b5643a7f9a2448f89df14355
1 file changed
+27
-1
git-checkout.sh
+27
-1
@@ -121,7 +121,33 @@ then
121
git-checkout-index -q -f -u -a
122
else
123
git-update-index --refresh >/dev/null
124
- git-read-tree -m -u $old $new
124
+ git-read-tree -m -u $old $new || (
125
+ echo >&2 -n "Try automerge [y/N]? "
126
+ read yesno
127
+ case "$yesno" in [yY]*) ;; *) exit 1 ;; esac
128
+
129
+ # NEEDSWORK: We may want to reset the index from the $new for
130
+ # these paths after the automerge happens, but it is not done
131
+ # yet. Probably we need to leave unmerged ones alone, and
132
+ # yank the object name & mode from $new for cleanly merged
133
+ # paths and stuff them in the index.
134
+
135
+ names=`git diff-files --name-only`
136
+ case "$names" in
137
+ '') ;;
138
+ *)
139
+ echo "$names" | git update-index --remove --stdin ;;
140
+ esac
141
+
142
+ work=`git write-tree` &&
143
+ git read-tree -m -u $old $work $new || exit
144
+ if result=`git write-tree 2>/dev/null`
145
+ then
146
+ echo >&2 "Trivially automerged." ;# can this even happen?
147
+ exit 0
148
+ fi
149
+ git merge-index -o git-merge-one-file -a
150
+ )
151
fi
152
153
#