summaryrefslogtreecommitdiff
path: root/git-pull.sh
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2009-08-11 23:27:40 -0400
committerJunio C Hamano <gitster@pobox.com>2009-08-12 15:50:09 -0700
commit19a7fcbf16276321f83e0c1748b3935a2ea42675 (patch)
treecd608b5e2aa4ec90785e355f830bc4880ac9be61 /git-pull.sh
parentefd17968387482f5765a969813707629b85bf74f (diff)
downloadgit-19a7fcbf16276321f83e0c1748b3935a2ea42675.tar.gz
allow pull --rebase on branch yet to be born
When doing a "pull --rebase", we check to make sure that the index and working tree are clean. The index-clean check compares the index against HEAD. The test erroneously reports dirtiness if we don't have a HEAD yet. In such an "unborn branch" case, by definition, a non-empty index won't be based on whatever we are pulling down from the remote, and will lose the local change. Just check if $GIT_DIR/index exists and error out. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-pull.sh')
-rwxr-xr-xgit-pull.sh18
1 files changed, 13 insertions, 5 deletions
diff --git a/git-pull.sh b/git-pull.sh
index 0f24182974..0bbd5bf7df 100755
--- a/git-pull.sh
+++ b/git-pull.sh
@@ -119,11 +119,19 @@ error_on_no_merge_candidates () {
}
test true = "$rebase" && {
- git update-index --ignore-submodules --refresh &&
- git diff-files --ignore-submodules --quiet &&
- git diff-index --ignore-submodules --cached --quiet HEAD -- ||
- die "refusing to pull with rebase: your working tree is not up-to-date"
-
+ if ! git rev-parse -q --verify HEAD >/dev/null
+ then
+ # On an unborn branch
+ if test -f "$GIT_DIR/index"
+ then
+ die "updating an unborn branch with changes added to the index"
+ fi
+ else
+ git update-index --ignore-submodules --refresh &&
+ git diff-files --ignore-submodules --quiet &&
+ git diff-index --ignore-submodules --cached --quiet HEAD -- ||
+ die "refusing to pull with rebase: your working tree is not up-to-date"
+ fi
oldremoteref= &&
. git-parse-remote &&
remoteref="$(get_remote_merge_branch "$@" 2>/dev/null)" &&