Skip to content

Conversation

@carlfriedrich
Copy link
Collaborator

@carlfriedrich carlfriedrich commented Jul 12, 2022

This PR improves gcp (cherry-pick) with the following features:

  1. Add FORGIT_CHERRY_PICK_FZF_OPTS
    The gcp command was the only command which did not have a variable to set command-specific fzf options. Add the according variable to source code and documentation.

  2. Preserve commit order on cherry pick
    When using a fzf find string which maches multiple lines, the commits could appear in a wrong order. Add --tiebreak=index to ensure that the correct commit order is preserved.

  3. Preserve +/- information on cherry pick
    The output of git cherry which is used to build the fzf input list for forgit::cherry::pick usually prefixes every line with a '-' for commits that have an equivalent in the target branch, and a '+' for commits that do not.
    Previously forgit removed this information from the list. However, for the actual cherry-picking process this information is relevant, so we should keep it.

  4. Reverse order on cherry pick
    glo displays the newest commits on top of the list, while gcp displays the newest commits at the bottom. Reverse the order of gcp so that it has the same order like glo.

Check list

  • I have performed a self-review of my code
  • I have commented my code in hard-to-understand areas
  • I have made corresponding changes to the documentation

Description

Type of change

  • Bug fix
  • New feature
  • Refactor
  • Breaking change
  • Documentation change

Test environment

  • Shell
    • bash
    • zsh
    • fish
  • OS
    • Linux
    • Mac OS X
    • Windows
    • Others:

The gcp (git cherry pick) command was the only command which did not
have a variable to set command-specific fzf options. Add the according
variable to source code and documentation.
When using a fzf find string which maches multiple lines, the commits
could appear in a wrong order. Add "--tiebreak=index" to ensure that the
correct commit order is preserved.
The output of 'git cherry' which is used to build the fzf input list for
forgit::cherry::pick usually prefixes every line with a '-' for commits
that have an equivalent in the target branch, and a '+' for commits that
do not.

Previously forgit removed this information from the list. However, for
the actual cherry-picking process this information is relevant, so we
should keep it.
@cjappl cjappl requested a review from wfxr July 12, 2022 17:53
@cjappl
Copy link
Collaborator

cjappl commented Jul 12, 2022

Love the improvements, just want to understand if we can replicate what tac does in a command that is available on both linux and mac!

@cjappl
Copy link
Collaborator

cjappl commented Jul 12, 2022

How about tail -r instead? Seems to work on my machine.


$ echo "hi
              hello
              world" | tail -r
world
hello
hi
$ echo "hi
              hello
              world" | /bin/cat
hi
hello
world

@wfxr
Copy link
Owner

wfxr commented Jul 13, 2022

@carlfriedrich Unfortunately gnu tail (on linux) doesn't support -r option.

❯ seq 10 | tail -r
tail: invalid option -- 'r'
Try 'tail --help' for more information.

Git log displays the newest commits on top of the list, while git cherry
pick displays the newest commits at the bottom. Reverse the order of
git cherry pick so that it has the same order like git log.
@carlfriedrich
Copy link
Collaborator Author

Hi @cjappl and @wfxr, thanks for your feedback. I have replaced tac with a combination of tac and tail -r, like proposed in this StackOverflow answer. Tested with bash and fish. Are you okay with that?

The alternative would be using sed or awk, but both would be significantly slower, which might make a difference on huge repos.

@cjappl
Copy link
Collaborator

cjappl commented Jul 13, 2022

Looks reasonable enough to me! will leave it to @wfxr to approve officially. Thanks for the adjustment

Copy link
Owner

@wfxr wfxr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@carlfriedrich LGTM.

Thank you!

@wfxr wfxr merged commit d2c2848 into wfxr:master Jul 14, 2022
@carlfriedrich carlfriedrich deleted the improve-cherry-pick branch July 26, 2022 06:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants