Skip to content

Commit 19205ac

Browse files
author
Junio C Hamano
committed
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>
1 parent 429608f commit 19205ac

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

git-checkout.sh

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,33 @@ then
121121
git-checkout-index -q -f -u -a
122122
else
123123
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+
)
125151
fi
126152

127153
#

0 commit comments

Comments
 (0)