Skip to content

Commit

Permalink
checkout: automerge local changes while switching branches.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Junio C Hamano committed Jan 14, 2006
1 parent 429608f commit 19205ac
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion git-checkout.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,33 @@ then
git-checkout-index -q -f -u -a
else
git-update-index --refresh >/dev/null
git-read-tree -m -u $old $new
git-read-tree -m -u $old $new || (
echo >&2 -n "Try automerge [y/N]? "
read yesno
case "$yesno" in [yY]*) ;; *) exit 1 ;; esac

# NEEDSWORK: We may want to reset the index from the $new for
# these paths after the automerge happens, but it is not done
# yet. Probably we need to leave unmerged ones alone, and
# yank the object name & mode from $new for cleanly merged
# paths and stuff them in the index.

names=`git diff-files --name-only`
case "$names" in
'') ;;
*)
echo "$names" | git update-index --remove --stdin ;;
esac

work=`git write-tree` &&
git read-tree -m -u $old $work $new || exit
if result=`git write-tree 2>/dev/null`
then
echo >&2 "Trivially automerged." ;# can this even happen?
exit 0
fi
git merge-index -o git-merge-one-file -a
)
fi

#
Expand Down

0 comments on commit 19205ac

Please sign in to comment.