Skip to content

Commit 08a0108

Browse files
committed
Merge branch 'pb/pull-rebase-autostash-fix' into seen
"git pull --rebase" ignored the rebase.autostash configuration variable when the remote history is a descendant of our history, which has been corrected. * pb/pull-rebase-autostash-fix: pull --rebase: honor rebase.autostash even when fast-forwarding
2 parents fe971d8 + 0385881 commit 08a0108

File tree

2 files changed

+55
-4
lines changed

2 files changed

+55
-4
lines changed

builtin/pull.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,14 +1038,13 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
10381038
oidclr(&orig_head);
10391039

10401040
if (opt_rebase) {
1041-
int autostash = config_autostash;
1042-
if (opt_autostash != -1)
1043-
autostash = opt_autostash;
1041+
if (opt_autostash == -1)
1042+
opt_autostash = config_autostash;
10441043

10451044
if (is_null_oid(&orig_head) && !is_cache_unborn())
10461045
die(_("Updating an unborn branch with changes added to the index."));
10471046

1048-
if (!autostash)
1047+
if (!opt_autostash)
10491048
require_clean_work_tree(the_repository,
10501049
N_("pull with rebase"),
10511050
_("please commit or stash them."), 1, 0);

t/t5521-pull-options.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,4 +252,56 @@ test_expect_success 'git pull --no-verify --verify passed to merge' '
252252
test_must_fail git -C dst pull --no-ff --no-verify --verify
253253
'
254254

255+
test_expect_success 'git pull --rebase --autostash succeeds on ff' '
256+
test_when_finished "rm -fr src dst actual" &&
257+
git init src &&
258+
test_commit -C src "initial" file "content" &&
259+
git clone src dst &&
260+
test_commit -C src --printf "more_content" file "more content\ncontent\n" &&
261+
echo "dirty" >>dst/file &&
262+
git -C dst pull --rebase --autostash >actual 2>&1 &&
263+
grep -q "Fast-forward" actual &&
264+
grep -q "Applied autostash." actual
265+
'
266+
267+
test_expect_success 'git pull --rebase with rebase.autostash succeeds on ff' '
268+
test_when_finished "rm -fr src dst actual" &&
269+
git init src &&
270+
test_commit -C src "initial" file "content" &&
271+
git clone src dst &&
272+
test_commit -C src --printf "more_content" file "more content\ncontent\n" &&
273+
echo "dirty" >>dst/file &&
274+
test_config -C dst rebase.autostash true &&
275+
git -C dst pull --rebase >actual 2>&1 &&
276+
grep -q "Fast-forward" actual &&
277+
grep -q "Applied autostash." actual
278+
'
279+
280+
test_expect_success 'git pull --rebase --autostash succeeds on non-ff' '
281+
test_when_finished "rm -fr src dst actual" &&
282+
git init src &&
283+
test_commit -C src "initial" file "content" &&
284+
git clone src dst &&
285+
test_commit -C src --printf "src_content" file "src content\ncontent\n" &&
286+
test_commit -C dst --append "dst_content" file "dst content" &&
287+
echo "dirty" >>dst/file &&
288+
git -C dst pull --rebase --autostash >actual 2>&1 &&
289+
grep -q "Successfully rebased and updated refs/heads/main." actual &&
290+
grep -q "Applied autostash." actual
291+
'
292+
293+
test_expect_success 'git pull --rebase with rebase.autostash succeeds on non-ff' '
294+
test_when_finished "rm -fr src dst actual" &&
295+
git init src &&
296+
test_commit -C src "initial" file "content" &&
297+
git clone src dst &&
298+
test_commit -C src --printf "src_content" file "src content\ncontent\n" &&
299+
test_commit -C dst --append "dst_content" file "dst content" &&
300+
echo "dirty" >>dst/file &&
301+
test_config -C dst rebase.autostash true &&
302+
git -C dst pull --rebase >actual 2>&1 &&
303+
grep -q "Successfully rebased and updated refs/heads/main." actual &&
304+
grep -q "Applied autostash." actual
305+
'
306+
255307
test_done

0 commit comments

Comments
 (0)