Skip to content

Commit 3c2bac9

Browse files
committed
Merge branch 'js/rebase-autostash-fix'
2 parents 3c9193e + b1811ac commit 3c2bac9

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

builtin/rebase.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,10 @@ static int apply_autostash(struct rebase_options *opts)
282282
if (!file_exists(path))
283283
return 0;
284284

285-
if (read_one(state_dir_path("autostash", opts), &autostash))
285+
if (read_one(path, &autostash))
286286
return error(_("Could not read '%s'"), path);
287+
/* Ensure that the hash is not mistaken for a number */
288+
strbuf_addstr(&autostash, "^0");
287289
argv_array_pushl(&stash_apply.args,
288290
"stash", "apply", autostash.buf, NULL);
289291
stash_apply.git_cmd = 1;
@@ -1531,7 +1533,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
15311533
update_index_if_able(&the_index, &lock_file);
15321534
rollback_lock_file(&lock_file);
15331535

1534-
if (has_unstaged_changes(0) || has_uncommitted_changes(0)) {
1536+
if (has_unstaged_changes(1) || has_uncommitted_changes(1)) {
15351537
const char *autostash =
15361538
state_dir_path("autostash", &options);
15371539
struct child_process stash = CHILD_PROCESS_INIT;
@@ -1557,7 +1559,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
15571559
if (safe_create_leading_directories_const(autostash))
15581560
die(_("Could not create directory for '%s'"),
15591561
options.state_dir);
1560-
write_file(autostash, "%s", buf.buf);
1562+
write_file(autostash, "%s", oid_to_hex(&oid));
15611563
printf(_("Created autostash: %s\n"), buf.buf);
15621564
if (reset_head(&head->object.oid, "reset --hard",
15631565
NULL, 0, NULL, NULL) < 0)

t/t3420-rebase-autostash.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,4 +351,14 @@ test_expect_success 'autostash is saved on editor failure with conflict' '
351351
test_cmp expected file0
352352
'
353353

354+
test_expect_success 'autostash with dirty submodules' '
355+
test_when_finished "git reset --hard && git checkout master" &&
356+
git checkout -b with-submodule &&
357+
git submodule add ./ sub &&
358+
test_tick &&
359+
git commit -m add-submodule &&
360+
echo changed >sub/file0 &&
361+
git rebase -i --autostash HEAD
362+
'
363+
354364
test_done

0 commit comments

Comments
 (0)