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

Allow changing directory within counsel-git #2740

Open
brownts opened this issue Dec 3, 2020 · 0 comments · May be fixed by #2750
Open

Allow changing directory within counsel-git #2740

brownts opened this issue Dec 3, 2020 · 0 comments · May be fixed by #2750

Comments

@brownts
Copy link
Contributor

brownts commented Dec 3, 2020

counsel-git uses the git root directory relative to the default-directory of the buffer (counsel-git > counsel-locate-git-root > counsel--git-root > counsel--dominating-file). However, if the buffer corresponds to a file which resides in a submodule, performing a git ls-files search (via counsel-git) will only show results for the current submodule, but not the parent or sibling submodules. Ideally, there should be a way to adjust the search directory, but there is no keymap for invoking counsel-cd from within the minibuffer, such as there is for counsel-git-grep.

If we could navigate to the top-most directory, we could perform a search this way...or really at any level of the nested git repository. This is what is being requested...the ability to invoke counsel-cd from counsel-git. A workaround would be to open a buffer corresponding to a file in the top-level git repository, however it is a nuisance to do this, and counsel-git-grep does not require this...it allows changing the directory. Thus, for a similar scenario (involving grep instead of find file) using counsel-git-grep it is straight forward (assuming "submodule.recurse=true" is configured for the repository) by just invoking C-x C-d from within the minibuffer and changing the directory up to the top-level directory.

For counsel-git, it could be as easy as it is for counsel-git-grep if counsel-cd were allowed to be invoked. One additional caveat to note is that git ls-files ignores the git config value of "submodule.recurse", apparently purposefully, as indicated here. However, this can be worked around by overriding the value of counsel-git-cmd and explicitly adding the "--recurse-submodules" option to that string.

The following is a test scenario which demonstrates the problem.

git Test Repository Scenario

mkdir ~/git/test-counsel-git-X
cd ~/git/test-counsel-git-X
git init
touch test_X.txt
git add --all
git commit -m "Initial Version"

mkdir ~/git/test-counsel-git-Y
cd ~/git/test-counsel-git-Y
git init
touch test_Y.txt
git add --all
git commit -a -m "Initial Version"

mkdir ~/git/test-counsel-git
cd ~/git/test-counsel-git
git init
touch test_main.txt
git submodule add ../test-counsel-git-X X
git submodule add ../test-counsel-git-Y Y
git add --all
git commit -m "Initial Version"

Test Scenario

  • make plain
  • C-x C-f ~/git/test-counsel-git/X/test_x.txt
  • M-x counsel-git test
    • Only shows "test_X.txt"
  • C-x C-f ~/git/test-counsel-git/test_main.txt
  • M-x counsel-git test
    • Only shows "test_main.txt" (since by default, git ls-files does not recurse through submodules).
  • M-: (setq counsel-git-cmd "git ls-files --recurse-submodules -z --full-name --")
    • Override counsel-git-cmd to add the --recurse-submodules option
  • M-x counsel-git test
    • Repeat with "test_main.txt" buffer
    • Now shows "X/test_X.txt, Y/test_Y.txt and test_main.txt", since it recurses through submodules.
  • C-x b test_x.txt
    • Switch back to test_x.txt buffer
  • M-x counsel-git test
    • Still only shows "test_X.txt" (since search begins at directory X)
    • No way to adjust search directory from this buffer.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants