Skip to content

Commit 1f35a91

Browse files
committed
Merge branch 'js/rebase-autostash-fix'
2 parents 84d2076 + 8e97b89 commit 1f35a91

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
@@ -251,8 +251,10 @@ static int apply_autostash(struct rebase_options *opts)
251251
if (!file_exists(path))
252252
return 0;
253253

254-
if (read_one(state_dir_path("autostash", opts), &autostash))
254+
if (read_one(path, &autostash))
255255
return error(_("Could not read '%s'"), path);
256+
/* Ensure that the hash is not mistaken for a number */
257+
strbuf_addstr(&autostash, "^0");
256258
argv_array_pushl(&stash_apply.args,
257259
"stash", "apply", autostash.buf, NULL);
258260
stash_apply.git_cmd = 1;
@@ -1353,7 +1355,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
13531355
update_index_if_able(&the_index, &lock_file);
13541356
rollback_lock_file(&lock_file);
13551357

1356-
if (has_unstaged_changes(0) || has_uncommitted_changes(0)) {
1358+
if (has_unstaged_changes(1) || has_uncommitted_changes(1)) {
13571359
const char *autostash =
13581360
state_dir_path("autostash", &options);
13591361
struct child_process stash = CHILD_PROCESS_INIT;
@@ -1379,7 +1381,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
13791381
if (safe_create_leading_directories_const(autostash))
13801382
die(_("Could not create directory for '%s'"),
13811383
options.state_dir);
1382-
write_file(autostash, "%s", buf.buf);
1384+
write_file(autostash, "%s", oid_to_hex(&oid));
13831385
printf(_("Created autostash: %s\n"), buf.buf);
13841386
if (reset_head(&head->object.oid, "reset --hard",
13851387
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)