require_work_tree
old_name=HEAD
-old=$(git-rev-parse --verify $old_name 2>/dev/null)
-oldbranch=$(git-symbolic-ref $old_name 2>/dev/null)
+old=$(git rev-parse --verify $old_name 2>/dev/null)
+oldbranch=$(git symbolic-ref $old_name 2>/dev/null)
new=
new_name=
force=
newbranch_log=
merge=
quiet=
+v=-v
LF='
'
while [ "$#" != "0" ]; do
shift
[ -z "$newbranch" ] &&
die "git checkout: -b needs a branch name"
- git-show-ref --verify --quiet -- "refs/heads/$newbranch" &&
+ git show-ref --verify --quiet -- "refs/heads/$newbranch" &&
die "git checkout: branch $newbranch already exists"
- git-check-ref-format "heads/$newbranch" ||
+ git check-ref-format "heads/$newbranch" ||
die "git checkout: we do not like '$newbranch' as a branch name."
;;
"-l")
;;
"-q")
quiet=1
+ v=
;;
--)
break
usage
;;
*)
- if rev=$(git-rev-parse --verify "$arg^0" 2>/dev/null)
+ if rev=$(git rev-parse --verify "$arg^0" 2>/dev/null)
then
if [ -z "$rev" ]; then
echo "unknown flag $arg"
exit 1
fi
- new="$rev"
new_name="$arg"
- if git-show-ref --verify --quiet -- "refs/heads/$arg"
+ if git show-ref --verify --quiet -- "refs/heads/$arg"
then
+ rev=$(git rev-parse --verify "refs/heads/$arg^0")
branch="$arg"
fi
- elif rev=$(git-rev-parse --verify "$arg^{tree}" 2>/dev/null)
+ new="$rev"
+ elif rev=$(git rev-parse --verify "$arg^{tree}" 2>/dev/null)
then
# checking out selected paths from a tree-ish.
new="$rev"
# from a specific tree-ish; note that this is for
# rescuing paths and is never meant to remove what
# is not in the named tree-ish.
- git-ls-tree --full-name -r "$new" "$@" |
- git-update-index --index-info || exit $?
+ git ls-tree --full-name -r "$new" "$@" |
+ git update-index --index-info || exit $?
fi
# Make sure the request is about existing paths.
- git-ls-files --error-unmatch -- "$@" >/dev/null || exit
- git-ls-files -- "$@" |
- git-checkout-index -f -u --stdin
+ git ls-files --error-unmatch -- "$@" >/dev/null || exit
+ git ls-files -- "$@" |
+ git checkout-index -f -u --stdin
exit $?
else
# Make sure we did not fall back on $arg^{tree} codepath
# but switching branches.
if test '' != "$new"
then
- git-rev-parse --verify "$new^{commit}" >/dev/null 2>&1 ||
+ git rev-parse --verify "$new^{commit}" >/dev/null 2>&1 ||
die "Cannot switch branch to a non-commit."
fi
fi
}
}
-if test -z "$branch$newbranch" && test "$new" != "$old"
+if test -z "$branch$newbranch" && test "$new_name" != "$old_name"
then
detached="$new"
if test -n "$oldbranch" && test -z "$quiet"
(now or later) by using -b with the checkout command again. Example:
git checkout -b <new_branch_name>"
fi
-elif test -z "$oldbranch"
+elif test -z "$oldbranch" && test "$new" != "$old"
then
describe_detached_head 'Previous HEAD position was' "$old"
fi
if [ "$force" ]
then
- git-read-tree --reset -u $new
+ git read-tree $v --reset -u $new
else
- git-update-index --refresh >/dev/null
- merge_error=$(git-read-tree -m -u --exclude-per-directory=.gitignore $old $new 2>&1) || (
+ git update-index --refresh >/dev/null
+ merge_error=$(git read-tree -m -u --exclude-per-directory=.gitignore $old $new 2>&1) || (
case "$merge" in
'')
echo >&2 "$merge_error"
esac
# Match the index to the working tree, and do a three-way.
- git diff-files --name-only | git update-index --remove --stdin &&
+ git diff-files --name-only | git update-index --remove --stdin &&
work=`git write-tree` &&
- git read-tree --reset -u $new || exit
+ git read-tree $v --reset -u $new || exit
eval GITHEAD_$new='${new_name:-${branch:-$new}}' &&
eval GITHEAD_$work=local &&
# this is not a real merge before committing, but just carrying
# the working tree changes along.
unmerged=`git ls-files -u`
- git read-tree --reset $new
+ git read-tree $v --reset $new
case "$unmerged" in
'') ;;
*)
(exit $saved_err)
fi
-#
+#
# Switch the HEAD pointer to the new branch if we
# checked out a branch head, and remove any potential
# old MERGE_HEAD's (subsequent commits will clearly not
#
if [ "$?" -eq 0 ]; then
if [ "$newbranch" ]; then
- git-branch $track $newbranch_log "$newbranch" "$new_name" || exit
+ git branch $track $newbranch_log "$newbranch" "$new_name" || exit
branch="$newbranch"
fi
if test -n "$branch"
then
- GIT_DIR="$GIT_DIR" git-symbolic-ref -m "checkout: moving to $branch" HEAD "refs/heads/$branch"
+ old_branch_name=`expr "z$oldbranch" : 'zrefs/heads/\(.*\)'`
+ GIT_DIR="$GIT_DIR" git symbolic-ref -m "checkout: moving from $old_branch_name to $branch" HEAD "refs/heads/$branch"
if test -n "$quiet"
then
true # nothing
fi
elif test -n "$detached"
then
- # NEEDSWORK: we would want a command to detach the HEAD
- # atomically, instead of this handcrafted command sequence.
- # Perhaps:
- # git update-ref --detach HEAD $new
- # or something like that...
- #
- git-rev-parse HEAD >"$GIT_DIR/HEAD.new" &&
- mv "$GIT_DIR/HEAD.new" "$GIT_DIR/HEAD" &&
- git-update-ref -m "checkout: moving to $arg" HEAD "$detached" ||
+ git update-ref --no-deref -m "checkout: moving to $arg" HEAD "$detached" ||
die "Cannot detach HEAD"
if test -n "$detach_warn"
then