]> git.ipfire.org Git - thirdparty/git.git/commit
sequencer: handle unborn branch with `--allow-empty`
authorBrian Lyles <brianmlyles@gmail.com>
Mon, 25 Mar 2024 23:16:51 +0000 (18:16 -0500)
committerJunio C Hamano <gitster@pobox.com>
Mon, 25 Mar 2024 23:45:40 +0000 (16:45 -0700)
commit1b90588d620a2970c82025c272e14f32d5e5969d
tree4cc85f24155fc27982bf6ca2e8778069253d51f0
parentc282eba2d561b726e4a60c8837e4eaa2ac6537fa
sequencer: handle unborn branch with `--allow-empty`

When using git-cherry-pick(1) with `--allow-empty` while on an unborn
branch, an error is thrown. This is inconsistent with the same
cherry-pick when `--allow-empty` is not specified.

Detect unborn branches in `is_index_unchanged`. When on an unborn
branch, use the `empty_tree` as the tree to compare against.

Add a new test to cover this scenario. While modelled off of the
existing 'cherry-pick on unborn branch' test, some improvements can be
made:

- Use `git switch --orphan unborn` instead of `git checkout --orphan
  unborn` to avoid the need for a separate `rm -rf *` call
- Avoid using `--quiet` in the `git diff` call to make debugging easier
  in the event of a failure. Use simply `--exit-code` instead.

Make these improvements to the existing test as well as the new test.

Helped-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Brian Lyles <brianmlyles@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
sequencer.c
t/t3501-revert-cherry-pick.sh