git-fuzzy icon indicating copy to clipboard operation
git-fuzzy copied to clipboard

Status does not display diffs when relativePaths=false

Open micampe opened this issue 1 year ago • 2 comments

I realize this is a real corner case but the fix seems to be simple.

Context: for my dotfiles I use a bare repository and a shell alias to call git with custom work tree and git dir flags: git --work-tree=$HOME --git-dir=$HOME/src/dotfiles.git $@.

git-fuzzy works fine with this except if I set status.relativePaths=false the diff in the status view is empty when I run it not from my home directory.

I understand it's a complicated setup, hope I explained clearly enough.

This happens because the preview diffs in gf_helper_status_preview_content() are being done from the current directory, and the paths are from the root of the repository.

I am not sure it is the correct solution but this fixes the problem for me:

diff --git a/lib/modules/status.sh b/lib/modules/status.sh
index 95c8228..c484fdf 100644
--- a/lib/modules/status.sh
+++ b/lib/modules/status.sh
@@ -59,6 +59,7 @@ gf_status_interpreter() {
 gf_status() {
   gf_snapshot "status"
   if [ -n "$(git status -s)" ]; then
+    gf_go_to_git_root_directory
     # shellcheck disable=2086
     git fuzzy helper status_menu_content | gf_fzf_status | gf_status_interpreter
   else

another option would be to change gf_helper_status_preview_content() to prepend $GIT_DIR to the file paths.

Great tool, thank you!

micampe avatar Nov 02 '23 08:11 micampe

Thanks for the feedback.

This is a complex issue because I often use git fuzzy like this:

$ vim $(git fuzzy status)

This means that if you're somewhere in your repo, you want the paths to be relative. OTOH, doing this with git fuzzy diff results in paths that are relative to the repo-root. It does make sense to make those consistent, but I haven't given it much thought.

I think this is a more general problem that needs a solution in the form of an env var. I was thinking something along the lines of GF_GIT_CONFIG_FOR_<command>_<context>. This means that you'd be able to set it like so:

GF_GIT_CONFIG_FOR_STATUS_MENU='--config status.relativePaths=false'

Because git-fuzzy supports project-specific settings, you could easily customize this per-repo.

Let me know what you think of this solution. I think it strikes the right balance of using git defaults while allowing the flexibility you want.

bigH avatar Nov 02 '23 20:11 bigH

Right, I didn't think about that. It would have to return a different value than what is displayed.

I'm not sure my specific case warrants the added complexity of these new options. If mine would be the only use case for this I don't think it's important enough, I can leave relativePaths, it's a minor cosmetic change.

If there is no solution without adding new configuration options I think this can be closed.

micampe avatar Nov 02 '23 22:11 micampe