{"thread":{"id":"24038","subject":"Re: Git Interactive Rebase - Bug in error message ?","startedAt":"2010-06-08T00:06:30Z","lastAt":"2010-06-08T08:16:11Z","messageCount":2,"participants":["Matthieu Tourne","Ian Ward Comfort"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"143197","messageId":"AANLkTinaUiHz8gRi5JF3n45aNCoPqiNxwExIga-cyYnw@mail.gmail.com","threadId":"24038","inReplyTo":"AANLkTikIKILZaGC9WZ45ZUC-lxeYIb3Mrf38qwlS2bVr@mail.gmail.com","subject":"Re: Git Interactive Rebase - Bug in error message ?","fromName":"Matthieu Tourne","fromEmail":"matthieu.tourne@gmail.com","sentAt":"2010-06-08T00:06:30Z","receivedAt":"2010-06-08T00:06:30Z","isPatch":false,"sender":{"key":"matthieu.tourne@gmail.com","avatar":null},"body":"Hi,\n\nI tried to perform an interactive rebase of several commits in my tree.\nIn one of my commits I had performed a git rm --cached, on several files.\nThe resulting message was :\n\nerror: Untracked working tree file 'foo' would be overwritten by merge.\nshift: 1: can't shift that many\n\nI eventually removed the file from the fs, and the rebase worked.\nThe fact that the rebase is not working is probably not a bug, but the\nlast line looks like an sh bug.\n\nI can reproduce this with git 1.7.1, and also git HEAD (1.7.1.245.g7c42e)\n\n\nthis can be reproduced with :\n\n$ mkdir dirA\n$ echo \"A\" > dirA/A\n$ git commit -a -m 'first commit'\n\n$ mkdir dirB\n$ echo \"B\" > dirB/B\n$ git commit -a -m 'creating dirB'\n\n$ mkdir dirC\n$ echo \"C\" > dirC/C\n$ git rm -r --cached dirA\n$ git commit -a -m 'creating dirC, removing dirA'\n\n$ git rebase --interactive HEAD~2\n(then swapping the two commits)\n\npick creating dirC, removing dirA\npick creating dirB\n\nerror: Untracked working tree file 'dirA/A' would be overwritten by merge.\nshift: 1: can't shift that many\n\n\nThank you,\n\nMatthieu.\n\n-- \nMatthieu Tourne\n"},{"id":"143215","messageId":"1275984971-20444-1-git-send-email-icomfort@stanford.edu","threadId":"24038","inReplyTo":"AANLkTinaUiHz8gRi5JF3n45aNCoPqiNxwExIga-cyYnw@mail.gmail.com","subject":"[PATCH] rebase -i: Abort cleanly if new base cannot be checked out","fromName":"Ian Ward Comfort","fromEmail":"icomfort@stanford.edu","sentAt":"2010-06-08T08:16:11Z","receivedAt":"2010-06-08T08:16:11Z","isPatch":true,"sender":{"key":"icomfort@stanford.edu","avatar":"https://avatars.githubusercontent.com/u/202841?v=4"},"body":"On 7 Jun 2010, at 5:06 PM, Matthieu Tourne wrote:\n> I tried to perform an interactive rebase of several commits in my tree.\n> In one of my commits I had performed a git rm --cached, on several files.\n> The resulting message was :\n>\n> error: Untracked working tree file 'foo' would be overwritten by merge.\n> shift: 1: can't shift that many\n>\n> I eventually removed the file from the fs, and the rebase worked.\n> The fact that the rebase is not working is probably not a bug, but the\n> last line looks like an sh bug.\n\nThe last line is a side effect of dash, which apparently complains when asked\nto shift from an empty array, and it shouldn't be there. The best fix, though,\nisn't to silence shift but to eliminate that code path by fixing another bug\nin rebase--interactive. In the scenario you describe, git currently leaves the\nrepository in the middle of an impossible rebase, with questionably-consistent\nstate in .git/rebase-merge. The behavior is more compactly (if more\nnonsensically) exhibited with:\n\n  $ git init test && cd test\n  $ touch A\n  $ git add A\n  $ git commit -m 'add' A\n  $ git rm --cached A\n  $ git commit -m 'remove'\n  $ GIT_EDITOR=: git rebase -i --no-ff HEAD^\n\nLet's abort cleanly instead, since that's what non-interactive rebase does\nalready.\n\n---- 8< ----\n\nUntracked content in the working tree may prevent rebase -i from checking out\nthe new base onto which it wants to replay commits, if the new base commit\nincludes files at those (now untracked) paths. Currently, rebase -i dies\nuncleanly in this situation, updating ORIG_HEAD and leaving a useless\n.git/rebase-merge directory, with which the user can do nothing useful except\nrebase --abort. Make rebase -i abort the procedure itself instead, as\nnon-interactive rebase already does, and add a test for this behavior.\n\nSigned-off-by: Ian Ward Comfort <icomfort@stanford.edu>\n---\n git-rebase--interactive.sh    |    3 ++-\n t/t3404-rebase-interactive.sh |   10 ++++++++++\n 2 files changed, 12 insertions(+), 1 deletions(-)\n\ndiff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh\nindex 436b7f5..6b86abc 100755\n--- a/git-rebase--interactive.sh\n+++ b/git-rebase--interactive.sh\n@@ -974,8 +974,9 @@ EOF\n \n \t\ttest -d \"$REWRITTEN\" || test -n \"$NEVER_FF\" || skip_unnecessary_picks\n \n+\t\toutput git checkout $ONTO || die_abort \"could not detach HEAD\"\n \t\tgit update-ref ORIG_HEAD $HEAD\n-\t\toutput git checkout $ONTO && do_rest\n+\t\tdo_rest\n \t\t;;\n \tesac\n \tshift\ndiff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh\nindex f20ea38..8d40915 100755\n--- a/t/t3404-rebase-interactive.sh\n+++ b/t/t3404-rebase-interactive.sh\n@@ -146,6 +146,16 @@ test_expect_success 'abort' '\n \t! test -d .git/rebase-merge\n '\n \n+test_expect_success 'abort with error when new base cannot be checked out' '\n+\tgit rm --cached file1 &&\n+\tgit commit -m \"remove file in base\" &&\n+\ttest_must_fail git rebase -i master > output 2>&1 &&\n+\tgrep \"Untracked working tree file .file1. would be overwritten\" \\\n+\t\toutput &&\n+\t! test -d .git/rebase-merge &&\n+\tgit reset --hard HEAD^\n+'\n+\n test_expect_success 'retain authorship' '\n \techo A > file7 &&\n \tgit add file7 &&\n-- \n1.7.1\n"}]}