Skip to content

Commit

Permalink
builtin/pull.c: use config value of autostash
Browse files Browse the repository at this point in the history
A bug in pull.c causes merge and rebase functions to ignore
rebase.autostash if it is only set in the config.

Move autostash to be file scoped, and use it in merge and rebase
functions.

Signed-Off-By: "John Cai" <johncai86@gmail.com>
  • Loading branch information
john-cai authored and John Cai committed Jan 4, 2022
1 parent 194610f commit ecd7177
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 5 deletions.
11 changes: 6 additions & 5 deletions builtin/pull.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ static char *opt_ff;
static char *opt_verify_signatures;
static char *opt_verify;
static int opt_autostash = -1;
static int autostash = 0;
static int config_autostash;
static int check_trust_level = 1;
static struct strvec opt_strategies = STRVEC_INIT;
Expand Down Expand Up @@ -687,9 +688,9 @@ static int run_merge(void)
strvec_pushv(&args, opt_strategy_opts.v);
if (opt_gpg_sign)
strvec_push(&args, opt_gpg_sign);
if (opt_autostash == 0)
if (autostash == 0)
strvec_push(&args, "--no-autostash");
else if (opt_autostash == 1)
else if (autostash == 1)
strvec_push(&args, "--autostash");
if (opt_allow_unrelated_histories > 0)
strvec_push(&args, "--allow-unrelated-histories");
Expand Down Expand Up @@ -899,9 +900,9 @@ static int run_rebase(const struct object_id *newbase,
strvec_push(&args, opt_gpg_sign);
if (opt_signoff)
strvec_push(&args, opt_signoff);
if (opt_autostash == 0)
if (autostash == 0)
strvec_push(&args, "--no-autostash");
else if (opt_autostash == 1)
else if (autostash == 1)
strvec_push(&args, "--autostash");
if (opt_verify_signatures &&
!strcmp(opt_verify_signatures, "--verify-signatures"))
Expand Down Expand Up @@ -1038,7 +1039,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
oidclr(&orig_head);

if (opt_rebase) {
int autostash = config_autostash;
autostash = config_autostash;
if (opt_autostash != -1)
autostash = opt_autostash;

Expand Down
51 changes: 51 additions & 0 deletions t/t5521-pull-options.sh
Original file line number Diff line number Diff line change
Expand Up @@ -251,5 +251,56 @@ test_expect_success 'git pull --no-verify --verify passed to merge' '
test_commit -C src two &&
test_must_fail git -C dst pull --no-ff --no-verify --verify
'
test_expect_success 'git pull --rebase --autostash succeeds on ff' '
test_when_finished "rm -fr src dst actual" &&
git init src &&
test_commit -C src "initial" file "content" &&
git clone src dst &&
test_commit -C src --printf "more_content" file "more content\ncontent\n" &&
echo "dirty" >>dst/file &&
git -C dst pull --rebase --autostash >actual 2>&1 &&
grep -q "Fast-forward" actual &&
grep -q "Applied autostash." actual
'

test_expect_success 'git pull --rebase with rebase.autostash succeeds on ff' '
test_when_finished "rm -fr src dst actual" &&
git init src &&
test_commit -C src "initial" file "content" &&
git clone src dst &&
test_commit -C src --printf "more_content" file "more content\ncontent\n" &&
echo "dirty" >>dst/file &&
test_config -C dst rebase.autostash true &&
git -C dst pull --rebase >actual 2>&1 &&
grep -q "Fast-forward" actual &&
grep -q "Applied autostash." actual
'

test_expect_success 'git pull --rebase --autostash succeeds on non-ff' '
test_when_finished "rm -fr src dst actual" &&
git init src &&
test_commit -C src "initial" file "content" &&
git clone src dst &&
test_commit -C src --printf "src_content" file "src content\ncontent\n" &&
test_commit -C dst --append "dst_content" file "dst content" &&
echo "dirty" >>dst/file &&
git -C dst pull --rebase --autostash >actual 2>&1 &&
grep -q "Successfully rebased and updated refs/heads/main." actual &&
grep -q "Applied autostash." actual
'

test_expect_success 'git pull --rebase with rebase.autostash succeeds on non-ff' '
test_when_finished "rm -fr src dst actual" &&
git init src &&
test_commit -C src "initial" file "content" &&
git clone src dst &&
test_commit -C src --printf "src_content" file "src content\ncontent\n" &&
test_commit -C dst --append "dst_content" file "dst content" &&
echo "dirty" >>dst/file &&
test_config -C dst rebase.autostash true &&
git -C dst pull --rebase >actual 2>&1 &&
grep -q "Successfully rebased and updated refs/heads/main." actual &&
grep -q "Applied autostash." actual
'

test_done

0 comments on commit ecd7177

Please sign in to comment.