wfxr / forgit

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

[question]: how to add flag `--follow` when running command `glo` for `git log` #281

Closed Clumsy-Coder closed 1 year ago

Clumsy-Coder commented 1 year ago

Check list

Environment info

Question

How do I add the flag --follow when running git log for the alias glo?

Why? Ans) I would like to see the logs of a file before it moved or renamed.

https://github.com/wfxr/forgit/blob/be8c306c18754f6ede2955f901b832a3225d4b83/bin/git-forgit#L74-L97

From what I see, there's no ENV used for modifiying the git log command to add the --follow flag.

cjappl commented 1 year ago

There is no way to do this via a config value, but you could add it to the line here possibly

eval "git log --follow $graph --color=always --format='$log_format' $* $_forgit_emojify" |

We could consider adding it as an option in the future, like we do for --graph if enough people think it would be useful

sandr01d commented 1 year ago

Does glo --follow -- FILESPEC not work? Forgit passes the options on to git log with $*. Or am I missing something here?

cjappl commented 1 year ago

Interesting, maybe true! We use the argv variable $* a couple times in the function

     files=$(sed -nE 's/.* -- (.*)/\1/p' <<< "$*") # extract files parameters for `git show` command 

     eval "git log $graph --color=always --format='$log_format' $* $_forgit_emojify" | 

I'm not sure if the first one would choke on that flag? It's worth a try though @Clumsy-Coder . Do report back if you find out :)

Clumsy-Coder commented 1 year ago

I tried the command to display the entire history of a file.

glo --follow <file>

I got this.

image

Not sure what the ... thing is. When using the arrow keys to navigate the commits, ... display nothing on the right side

sandr01d commented 1 year ago

That's git telling you that it left out some commits because the file you specified wasn't modified in those. We could make sure that only lines actually containing a commit get displayed by adding a grep command like this

    eval "git log $graph --color=always --format='$log_format' $* $_forgit_emojify" |
        grep '\*' |
        FZF_DEFAULT_OPTS="$opts" fzf

This would also get rid of lines containing only things like |/. Before the change glo looks like this

image

After the change like this:

image

I'd personally prefer the second one and can provide a PR if this is the behavior we want. Opinions?

sandr01d commented 1 year ago

Interesting, maybe true! We use the argv variable $* a couple times in the function

     files=$(sed -nE 's/.* -- (.*)/\1/p' <<< "$*") # extract files parameters for `git show` command 

     eval "git log $graph --color=always --format='$log_format' $* $_forgit_emojify" | 

I'm not sure if the first one would choke on that flag? It's worth a try though @Clumsy-Coder . Do report back if you find out :)

Should be fine. The sed command only matches when there is a space after the --.

carlfriedrich commented 1 year ago

@Clumsy-Coder Do I understand it right that calling glo --follow <file> actually answers your question?

carlfriedrich commented 1 year ago

That's git telling you that it left out some commits because the file you specified wasn't modified in those. We could make sure that only lines actually containing a commit get displayed by adding a grep command like this

    eval "git log $graph --color=always --format='$log_format' $* $_forgit_emojify" |
        grep '\*' |
        FZF_DEFAULT_OPTS="$opts" fzf

This would also get rid of lines containing only things like |/. Before the change glo looks like this

image

After the change like this:

image

I'd personally prefer the second one and can provide a PR if this is the behavior we want. Opinions?

@sandr01d I personally prefer the first one and would like to keep this information in the log. So if you want to provide a PR for this, I would prefer to have it as an opt-in option.

Clumsy-Coder commented 1 year ago

@carlfriedrich It mostly solves it, but a small issue remains where you have ... on commits that are not related to the file being viewed.

https://github.com/wfxr/forgit/issues/281#issuecomment-1400820232

image

sandr01d commented 1 year ago

@carlfriedrich It mostly solves it, but a small issue remains where you have ... on commits that are not related to the file being viewed.

#281 (comment)

image

Does FORGIT_LOG_GRAPH_ENABLE=false glo --follow FILESPEC provide your desired output?

sandr01d commented 1 year ago

That's git telling you that it left out some commits because the file you specified wasn't modified in those. We could make sure that only lines actually containing a commit get displayed by adding a grep command like this

    eval "git log $graph --color=always --format='$log_format' $* $_forgit_emojify" |
        grep '\*' |
        FZF_DEFAULT_OPTS="$opts" fzf

This would also get rid of lines containing only things like |/. Before the change glo looks like this image After the change like this: image I'd personally prefer the second one and can provide a PR if this is the behavior we want. Opinions?

@sandr01d I personally prefer the first one and would like to keep this information in the log. So if you want to provide a PR for this, I would prefer to have it as an opt-in option.

Found this to be solved by FORGIT_LOG_GRAPH_ENABLE already, so no additional changes are necessary.

Clumsy-Coder commented 1 year ago

Does FORGIT_LOG_GRAPH_ENABLE=false glo --follow FILESPEC provide your desired output?

@sandr01d This solves the issue. maybe sometime later I could use it with the graph as well.