{"thread":{"id":"54907","subject":"[Bug report] Git gets stuck in rebase mode","startedAt":"2020-12-30T21:43:36Z","lastAt":"2020-12-31T23:58:10Z","messageCount":2,"participants":["LeSeulArtichaut","René Scharfe"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"413200","messageId":"ECF77241-0631-45D6-8B79-4250EE777A5D@gmail.com","threadId":"54907","inReplyTo":null,"subject":"[Bug report] Git gets stuck in rebase mode","fromName":"LeSeulArtichaut","fromEmail":"leseulartichaut@gmail.com","sentAt":"2020-12-30T21:41:44Z","receivedAt":"2020-12-30T21:43:36Z","isPatch":false,"sender":{"key":"leseulartichaut@gmail.com","avatar":null},"body":"What did you do before the bug happened? (Steps to reproduce your issue)\n\nI tried to rebase a branch, say `master`, onto a commit that does not exist in my local repository, say `37b52f3b750b11b9ef60db118f737a66af3bf242`:\n`git rebase master 37b52f3b750b11b9ef60db118f737a66af3bf242`\n\n- The branch has to be valid (e.g. `git rebase foo 37b52f3b750b11b9ef60db118f737a66af3bf242` doesn’t reproduce the bug)\n- The commit SHA has to be a full SHA (e.g. `git rebase master 37b52f3b750b11b9ef60db118f737a66af3bf2 #42` doesn’t reproduce the bug)\n\nRepro \"from scratch\":\n```zsh\nmkdir git-bug\ncd git-bug\ngit init\ntouch foo.txt\ngit add foo.txt\ngit commit -m 'Initial commit'\ngit rebase master 37b52f3b750b11b9ef60db118f737a66af3bf242\n```\n\nWhat did you expect to happen? (Expected behavior)\nGit either successfully applies the rebase or gives an error.\n\nWhat happened instead? (Actual behavior)\n```\nerror: Could not read 37b52f3b750b11b9ef60db118f737a66af3bf242\nfatal: Invalid symmetric difference expression b91ebd8a08983ed5c27a3946821be02a39f99b3c…37b52f3b750b11b9ef60db118f737a66af3bf242\n```\n\nGit then instead gets « stuck » in rebase mode (i.e. a `.git/rebase-merge` directory exists), with the following visible effects:\n - `git status` kind of gets confused:\n```bash\n$ git status\nOn branch master\ngit-rebase-todo is missing.\nNo commands done.\nNo commands remaining.\nYou are currently editing a commit during a rebase.\n  (use \"git commit --amend\" to amend the current commit)\n  (use \"git rebase --continue\" once you are satisfied with your changes)\n\nnothing to commit, working tree clean\n```\n - powerlevel10k displays a `rebase-i` state\n - `git rebase --continue` and `git rebase --abort` fail:\n```bash\n$ git rebase --continue\nerror: could not open '.git/rebase-merge/git-rebase-todo': No such file or directory\n$ git rebase --abort\nfatal: unable to read tree 37b52f3b750b11b9ef60db118f737a66af3bf242\n```\n\nThis disappears by deleting the `.git/rebase-merge` directory.\n\nWhat's different between what you expected and what actually happened?\nI didn’t expect Git to stay stuck in rebase. After the failure in the `rebase` command, the `.git/rebase-merge` directory should be deleted.\n\n\n[System Info]\ngit version:\ngit version 2.30.0\ncpu: x86_64\nno commit associated with this build\nsizeof-long: 8\nsizeof-size_t: 8\nshell-path: /bin/sh\nuname: Darwin 19.6.0 Darwin Kernel Version 19.6.0: Tue Nov 10 00:10:30 PST 2020; root:xnu-6153.141.10~1/RELEASE_X86_64 x86_64\ncompiler info: clang: 12.0.0 (clang-1200.0.32.28)\nlibc info: no libc information available\n$SHELL (typically, interactive shell): /bin/zsh\n\n\n[Enabled Hooks]\n"},{"id":"413227","messageId":"49e25873-90e0-8ae2-7a40-01bec3f99e5f@web.de","threadId":"54907","inReplyTo":"ECF77241-0631-45D6-8B79-4250EE777A5D@gmail.com","subject":"[PATCH] rebase: verify commit parameter","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2020-12-31T23:55:12Z","receivedAt":"2020-12-31T23:58:10Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"If the user specifies a base commit to switch to, check if it actually\nreferences a commit right away to avoid getting confused later on when\nit turns out to be an invalid object.\n\nReported-by: LeSeulArtichaut <leseulartichaut@gmail.com>\nSigned-off-by: René Scharfe <l.s.r@web.de>\n---\ngit-legacy-rebase.sh also accepted non-commits, if I read the code\ncorrectly.\n\n builtin/rebase.c | 4 +++-\n 1 file changed, 3 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/rebase.c b/builtin/rebase.c\nindex 19c7b377aa..840dbd7eb7 100644\n--- a/builtin/rebase.c\n+++ b/builtin/rebase.c\n@@ -1917,7 +1917,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)\n \t\t\tdie_if_checked_out(buf.buf, 1);\n \t\t\toptions.head_name = xstrdup(buf.buf);\n \t\t/* If not is it a valid ref (branch or commit)? */\n-\t\t} else if (!get_oid(branch_name, &options.orig_head))\n+\t\t} else if (!get_oid(branch_name, &options.orig_head) &&\n+\t\t\t   lookup_commit_reference(the_repository,\n+\t\t\t\t\t\t   &options.orig_head))\n \t\t\toptions.head_name = NULL;\n \t\telse\n \t\t\tdie(_(\"fatal: no such branch/commit '%s'\"),\n--\n2.30.0\n"}]}