lazygit/pkg/commands/git_commands
Stefan Haller 8b99a3c949 Drop update-ref commands at the top of the rebase-todo file
The rebase.updateRefs feature of git is very useful to rebase a stack of
branches and keep everything nicely stacked; however, it is usually in the way
when you make a copy of a branch and want to rebase it "away" from the original
branch in some way or other. For example, the original branch might sit on main,
and you want to rebase the copy onto devel to see if things still compile there.
Or you want to do some heavy history rewriting experiments on the copy, but keep
the original branch in case the experiments fail. Or you want to split a branch
in two because it contains two unrelated sets of changes; so you make a copy,
and drop half of the commits from the copy, then check out the original branch
and drop the other half of the commits from it.

In all these cases, git's updateRefs feature insists on moving the original
branch along with the copy in the first rebase that you make on the copy. I
think this is a bug in git, it should create update-ref todos only for branches
that point into the middle of your branch (because only then do they form a
stack), not when they point at the head (because then it's a copy). I had a long
discussion about this on the git mailing list [1], but people either don't agree
or don't care enough.

So we fix this on our side: whenever we start a rebase for whatever reason, be
it interactive, non-interactive, or behind-the-scenes, we drop any update-ref
todos that are at the very top of the todo list, which fixes all the
above-mentioned scenarios nicely.

I will admit that there's one scenario where git's behavior is the desired one,
and the fix in this PR makes it worse: when you create a new branch off of an
existing one, with the intention of creating a stack of branches, but before you
make the first commit on the new branch you realize some problem with the first
branch (e.g. a commit that needs to be reworded or dropped). It this case you do
want both branches to be affected by the change. In my experience this scenario
is much rarer than the other ones that I described above, and it's also much
easier to recover from: just check out the other branch again and hard-reset it
to the rebased one.

[1]
https://public-inbox.org/git/354f9fed-567f-42c8-9da9-148a5e223022@haller-berlin.de/
2024-04-22 20:59:15 +02:00
..
bisect.go rename sha to hash 9, case: Sha 2024-04-12 08:33:47 +02:00
bisect_info.go rename sha to hash 2 2024-04-12 08:33:47 +02:00
blame.go Add command to find base commit for creating a fixup 2024-01-10 09:11:40 +01:00
branch.go rename sha to hash 5 2024-04-12 08:33:47 +02:00
branch_loader.go Add a sort order menu for local branches 2023-12-27 15:25:29 +01:00
branch_loader_test.go Add a sort order menu for local branches 2023-12-27 15:25:29 +01:00
branch_test.go Break git.merging.args config into separate arguments on whitespace 2024-03-02 10:22:01 +01:00
commit.go rename sha to hash 5 2024-04-12 08:33:47 +02:00
commit_file_loader.go Set diff.noprefix=false for all other diff commands too 2024-02-18 15:22:43 +01:00
commit_file_loader_test.go Merge loaders package into git_commands package 2022-11-14 18:11:45 +11:00
commit_loader.go Switch git-todo-parser from fsmiamoto original repo to stefanhaller's fork 2024-04-22 20:59:15 +02:00
commit_loader_test.go Switch git-todo-parser from fsmiamoto original repo to stefanhaller's fork 2024-04-22 20:59:15 +02:00
commit_test.go rename sha to hash 10, last remaining sha (hopefully) 2024-04-12 08:33:47 +02:00
common.go Remove sync mutex 2023-10-08 18:45:36 +02:00
config.go Add UserConfig jsonschema generation script 2023-12-02 10:46:24 +01:00
custom.go Construct arg vector manually rather than parse string 2023-05-23 19:49:19 +10:00
deps_test.go Add AppState to common.Common 2023-09-04 17:48:39 +02:00
diff.go Set diff.noprefix=false for all other diff commands too 2024-02-18 15:22:43 +01:00
file.go Support editing multiple files at once using range selection 2024-03-22 08:20:16 +01:00
file_loader.go Write unit tests with the help of afero 2023-07-30 18:35:36 +10:00
file_loader_test.go Write unit tests with the help of afero 2023-07-30 18:35:36 +10:00
file_test.go Support editing multiple files at once using range selection 2024-03-22 08:20:16 +01:00
flow.go Construct arg vector manually rather than parse string 2023-05-23 19:49:19 +10:00
flow_test.go Construct arg vector manually rather than parse string 2023-05-23 19:49:19 +10:00
git_command_builder.go Show all submodules recursively 2024-03-07 20:16:28 +01:00
git_command_builder_test.go Add worktree tests for removing/detaching 2023-07-30 18:35:23 +10:00
patch.go Switch git-todo-parser from fsmiamoto original repo to stefanhaller's fork 2024-04-22 20:59:15 +02:00
rebase.go Drop update-ref commands at the top of the rebase-todo file 2024-04-22 20:59:15 +02:00
rebase_test.go rename sha to hash 2024-04-12 08:33:47 +02:00
reflog_commit_loader.go rename sha to hash 8, update some log and comment 2024-04-12 08:33:47 +02:00
reflog_commit_loader_test.go rename sha to hash 2024-04-12 08:33:47 +02:00
remote.go Obtain remote URL by calling "ls-remote --get-url" instead of using git config 2024-01-10 09:24:23 +01:00
remote_loader.go Implement a sort order menu for remote branches 2023-12-22 16:30:20 +09:00
repo_paths.go Refactor repo_paths.go to use git rev-parse 2024-01-24 08:40:01 +01:00
repo_paths_test.go Refactor repo_paths.go to use git rev-parse 2024-01-24 08:40:01 +01:00
stash.go rename sha to hash 2024-04-12 08:33:47 +02:00
stash_loader.go chore: use null char as a stash entries divider during loading 2023-12-27 11:21:49 +01:00
stash_loader_test.go feat: add age on stash lines 2023-12-27 11:21:49 +01:00
stash_test.go rename sha to hash 10, last remaining sha (hopefully) 2024-04-12 08:33:47 +02:00
status.go Add StatusCommands.IsInNormalRebase and IsInInteractiveRebase 2023-09-18 10:50:19 +02:00
submodule.go Show all submodules recursively 2024-03-07 20:16:28 +01:00
sync.go Allow multiple fetch commands (or fetch and pull) to run concurrently 2024-01-10 09:18:38 +01:00
sync_test.go Use an interface for tasks instead of a concrete struct 2023-07-10 17:12:21 +10:00
tag.go Remove sync mutex 2023-10-08 18:45:36 +02:00
tag_loader.go Standardise on using lo for slice functions 2023-07-30 18:51:23 +10:00
tag_loader_test.go Construct arg vector manually rather than parse string 2023-05-23 19:49:19 +10:00
version.go Add a method GitVersion.IsAtLeast 2024-01-10 09:18:38 +01:00
version_test.go Add a method GitVersion.IsAtLeast 2024-01-10 09:18:38 +01:00
working_tree.go renaming variable to CommitHash 2024-04-12 08:33:47 +02:00
working_tree_test.go renaming variable to CommitHash 2024-04-12 08:33:47 +02:00
worktree.go Centralise logic for obtaining repo paths 2023-07-30 18:35:24 +10:00
worktree_loader.go Refactor repo_paths.go to use git rev-parse 2024-01-24 08:40:01 +01:00
worktree_loader_test.go Refactor repo_paths.go to use git rev-parse 2024-01-24 08:40:01 +01:00