@matheusbsbs / matheus-bagliano / commits / 19a7fcbf16
Fork 0

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>

Jeff King committed Aug 11, 2009 at 23:27 UTC 19a7fcbf16276321f83e0c1748b3935a2ea42675
2 files changed +24 -5
git-pull.sh
+13 -5
@@ -119,11 +119,19 @@ error_on_no_merge_candidates () {
119 }
120
121 test true = "$rebase" && {
122 - git update-index --ignore-submodules --refresh &&
123 - git diff-files --ignore-submodules --quiet &&
124 - git diff-index --ignore-submodules --cached --quiet HEAD -- ||
125 - die "refusing to pull with rebase: your working tree is not up-to-date"
126 -
122 + if ! git rev-parse -q --verify HEAD >/dev/null
123 + then
124 + # On an unborn branch
125 + if test -f "$GIT_DIR/index"
126 + then
127 + die "updating an unborn branch with changes added to the index"
128 + fi
129 + else
130 + git update-index --ignore-submodules --refresh &&
131 + git diff-files --ignore-submodules --quiet &&
132 + git diff-index --ignore-submodules --cached --quiet HEAD -- ||
133 + die "refusing to pull with rebase: your working tree is not up-to-date"
134 + fi
135 oldremoteref= &&
136 . git-parse-remote &&
137 remoteref="$(get_remote_merge_branch "$@" 2>/dev/null)" &&
t/t5520-pull.sh
+11
@@ -149,4 +149,15 @@ test_expect_success 'pull --rebase dies early with dirty working directory' '
149
150 '
151
152 +test_expect_success 'pull --rebase works on branch yet to be born' '
153 + git rev-parse master >expect &&
154 + mkdir empty_repo &&
155 + (cd empty_repo &&
156 + git init &&
157 + git pull --rebase .. master &&
158 + git rev-parse HEAD >../actual
159 + ) &&
160 + test_cmp expect actual
161 +'
162 +
163 test_done