summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: efd1796)
raw | patch | inline | side by side (parent: efd1796)
author | Jeff King <peff@peff.net> | |
Wed, 12 Aug 2009 03:27:40 +0000 (23:27 -0400) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Wed, 12 Aug 2009 22:50:09 +0000 (15:50 -0700) |
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>
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>
git-pull.sh | patch | blob | history | |
t/t5520-pull.sh | patch | blob | history |
diff --git a/git-pull.sh b/git-pull.sh
index 0f24182974fe2040c950b846decf360c1c22dbb1..0bbd5bf7df185acd24302f9e5ce06e4a314d040a 100755 (executable)
--- a/git-pull.sh
+++ b/git-pull.sh
}
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)" &&
diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index e78d40242a80d9b2aa74e74d3a4aecddbb63ab99..dd2ee842e020c23b49ed4e2070c4e31cdb7ac055 100755 (executable)
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
'
+test_expect_success 'pull --rebase works on branch yet to be born' '
+ git rev-parse master >expect &&
+ mkdir empty_repo &&
+ (cd empty_repo &&
+ git init &&
+ git pull --rebase .. master &&
+ git rev-parse HEAD >../actual
+ ) &&
+ test_cmp expect actual
+'
+
test_done