Skip to content

Commit

Permalink
counsel.el: counsel--git-grep-count-func-default submodule support
Browse files Browse the repository at this point in the history
(counsel--git-grep-count-func-default): Ask Git where the .git directory
is for the repository in the current directory.

Modern Git puts all the git directories for submodules underneath the top
level `.git` directory and then leaves a "git-file" in the submodule which
points back to the repository inside the top-level .git directory. This
means, that within a submodule, the `.git` file contains something like:

 gitdir: ../../.git/modules/submodule-repo-name

counsel--git-grep-count-func-default runs "du -s .git 2>/dev/null" which is
bound to give a very small answer for just this small file.

So, let's ask Git to tell us where the real .git directory is and calculate
the size of that.

Fixes abo-abo#1558
  • Loading branch information
mikecrowe authored and abo-abo committed Jun 14, 2018
1 parent 6c9d3c2 commit c4e9d27
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion counsel.el
Expand Up @@ -1307,7 +1307,7 @@ files in a project.")
"Default defun to calculate `counsel--git-grep-count'."
(if (eq system-type 'windows-nt)
0
(read (shell-command-to-string "du -s .git 2>/dev/null"))))
(read (shell-command-to-string "du -s \"$(git rev-parse --git-dir)\" 2>/dev/null"))))

(defvar counsel--git-grep-count-func #'counsel--git-grep-count-func-default
"Defun to calculate `counsel--git-grep-count' for `counsel-git-grep'.")
Expand Down

0 comments on commit c4e9d27

Please sign in to comment.