Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git log --graph edges point the wrong way #71

Closed
5 of 10 tasks
jcassee opened this issue Jan 29, 2020 · 10 comments
Closed
5 of 10 tasks

git log --graph edges point the wrong way #71

jcassee opened this issue Jan 29, 2020 · 10 comments

Comments

@jcassee
Copy link

jcassee commented Jan 29, 2020

Check list

  • I have read through the README
  • I have the latest version of forgit
  • I have searched through the existing issues

Environment info

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

Problem / Steps to reproduce

The git log viewer calls git log --graph. Because the commits are shown bottom-up, the graph edges point the wrong way. See for example the log of forgit itself:

Schermafdruk van 2020-01-29 15-34-26

I don't think it is possible to have git output a reverse graph (--graph and --reverse are mutually exclusive). Maybe --graph should be omitted from the git log command?

@wfxr
Copy link
Owner

wfxr commented Feb 4, 2020

Thanks for your feedback @jcassee . I will check this after the vacation.

@wfxr
Copy link
Owner

wfxr commented Feb 17, 2020

Hi @jcassee . You're right, git doesn't provide such an option. There is a work around to make the graph reasonable when the commits are shown bottom-up:

forgit::log() {
    forgit::inside_work_tree || return 1
    local cmd opts full_opts flip
    cmd="echo {} |grep -Eo '[a-f0-9]+' |head -1 |xargs -I% git show --color=always % $* | $forgit_pager"
    opts="
        $FORGIT_FZF_DEFAULT_OPTS
        +s +m --tiebreak=index --preview=\"$cmd\"
        --bind=\"enter:execute($cmd | LESS='-R' less)\"
        --bind=\"ctrl-y:execute-silent(echo {} |grep -Eo '[a-f0-9]+' | head -1 | tr -d '\n' |${FORGIT_COPY_CMD:-pbcopy})\"
        $FORGIT_LOG_FZF_OPTS
    "
    full_opts="$FZF_DEFAULT_OPTS $opts"
    # if `reverse` option is NOT enabled, flip the '\' and '/' to make the log graph reasonable
    [[ $full_opts != *"--reverse"* ]] && [[ $full_opts != *"=reverse"* ]] && flip=true
    eval "git log --graph --color=always --format='%C(auto)%h%d %s %C(black)%C(bold)%cr' $* $forgit_emojify" |
        if [[ $flip == "true" ]]; then sed -e 's#/#{slash}#' -e 's#\\#/#' -e 's#{slash}#\\#'; else cat; fi |
        FZF_DEFAULT_OPTS="$opts" fzf
}

But before we have a better implementation I do not want to merge it into the code base. The main reason is we don't find a not complicated way to check if reverse option is enabled for fzf. The above code does simple string pattern matching but we are not sure whether --reverse is set for fzf itself or some commands inside fzf instead (eg. --preview='...--reverse...' ).

@jcassee
Copy link
Author

jcassee commented Feb 17, 2020

@wfxr Yeah, determining how fzf is used exactly is difficult. (By the way, the sed command would also switch slashes in the commit message, but that can be corrected.)

I know you did not want to, but maybe this is a good reason to allow customization of the git log command...?

@wfxr
Copy link
Owner

wfxr commented Feb 17, 2020

@jcassee sed replace only once per line unless g was specified at the end of replace pattern. So the above code will not switch slashes in the commit messages.

I understand your suggestion. Someone also mentioned this before. Because the extraction of the commit hash relies heavily on the output format of the git log I haven't adopted the suggestion before. But I will reconsider it.

I will keep this issue open and try to find a relatively reasonable solution.

@jcassee
Copy link
Author

jcassee commented Feb 17, 2020

sed replace only once per line unless g was specified at the end of replace pattern. So the above code will not switch slashes in the commit messages.

Good point. But that means it will only replace the first slash, while there may be multiple. 😄

Anyway, I understand you want to think it over some more. It's a subtle issue.

@omares
Copy link

omares commented Mar 27, 2020

Hey any progress on this issue? :) Is there maybe an option to turn off the graph output?

@wfxr wfxr mentioned this issue Mar 29, 2020
15 tasks
@wfxr
Copy link
Owner

wfxr commented Mar 29, 2020

@omares @jcassee Sorry for the late reply. Now you can disable the log graph by set FORGIT_LOG_GRAPH_ENABLE to false.

@cjappl
Copy link
Collaborator

cjappl commented Mar 30, 2020

I believe we can close this now @wfxr, fish has the appropriate behavior as well

@cjappl cjappl closed this as completed Mar 30, 2020
@jcassee
Copy link
Author

jcassee commented Mar 30, 2020

Thanks, @wfxr!

@akaralar
Copy link

akaralar commented May 13, 2020

just as a heads up, I faced the same thing and added this to my .zshrc before fzf or forgit is initialized:

export FORGIT_LOG_FZF_OPTS='--reverse'

It displays correctly, only the typing box of fzf is at the top instead of bottom, but otherwise it is good. Also since this makes the git history top-down, I believe this is more in line with how various git GUI tools are displaying a commit history & graph.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants