wfxr / forgit

:zzz: A utility tool powered by fzf for using git interactively.
MIT License
4.33k stars 136 forks source link

Improve cherry-pick #216

Closed carlfriedrich closed 1 year ago

carlfriedrich commented 1 year ago

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

Description

Type of change

Test environment

cjappl commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

@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.
carlfriedrich commented 1 year ago

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 commented 1 year ago

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