Skip to content

Commit

Permalink
Merge branch 'js/rebase-autostash-fix' into next
Browse files Browse the repository at this point in the history
"git rebase" that has recently been rewritten in C had a few issues
in its "--autstash" feature, which have been corrected.

* js/rebase-autostash-fix:
  rebase --autostash: fix issue with dirty submodules
  rebase --autostash: demonstrate a problem with dirty submodules
  rebase (autostash): use an explicit OID to apply the stash
  rebase (autostash): store the full OID in <state-dir>/autostash
  rebase (autostash): avoid duplicate call to state_dir_path()
  • Loading branch information
gitster committed Oct 29, 2018
2 parents 33641dc + ffae8b2 commit 680e648
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
8 changes: 5 additions & 3 deletions builtin/rebase.c
Expand Up @@ -251,8 +251,10 @@ static int apply_autostash(struct rebase_options *opts)
if (!file_exists(path))
return 0;

if (read_one(state_dir_path("autostash", opts), &autostash))
if (read_one(path, &autostash))
return error(_("Could not read '%s'"), path);
/* Ensure that the hash is not mistaken for a number */
strbuf_addstr(&autostash, "^0");
argv_array_pushl(&stash_apply.args,
"stash", "apply", autostash.buf, NULL);
stash_apply.git_cmd = 1;
Expand Down Expand Up @@ -1349,7 +1351,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
update_index_if_able(&the_index, &lock_file);
rollback_lock_file(&lock_file);

if (has_unstaged_changes(0) || has_uncommitted_changes(0)) {
if (has_unstaged_changes(1) || has_uncommitted_changes(1)) {
const char *autostash =
state_dir_path("autostash", &options);
struct child_process stash = CHILD_PROCESS_INIT;
Expand All @@ -1375,7 +1377,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
if (safe_create_leading_directories_const(autostash))
die(_("Could not create directory for '%s'"),
options.state_dir);
write_file(autostash, "%s", buf.buf);
write_file(autostash, "%s", oid_to_hex(&oid));
printf(_("Created autostash: %s\n"), buf.buf);
if (reset_head(&head->object.oid, "reset --hard",
NULL, 0, NULL, NULL) < 0)
Expand Down
10 changes: 10 additions & 0 deletions t/t3420-rebase-autostash.sh
Expand Up @@ -351,4 +351,14 @@ test_expect_success 'autostash is saved on editor failure with conflict' '
test_cmp expected file0
'

test_expect_success 'autostash with dirty submodules' '
test_when_finished "git reset --hard && git checkout master" &&
git checkout -b with-submodule &&
git submodule add ./ sub &&
test_tick &&
git commit -m add-submodule &&
echo changed >sub/file0 &&
git rebase -i --autostash HEAD
'

test_done

0 comments on commit 680e648

Please sign in to comment.