mirror of
https://github.com/git/git.git
synced 2024-11-24 10:26:17 +08:00
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>
This commit is contained in:
parent
efd1796838
commit
19a7fcbf16
18
git-pull.sh
18
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)" &&
|
||||
|
@ -149,4 +149,15 @@ test_expect_success 'pull --rebase dies early with dirty working directory' '
|
||||
|
||||
'
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user