Skip to content

Commit

Permalink
Try to detect SCM roots a little less strictly
Browse files Browse the repository at this point in the history
This change was driven by working inside Git submodules. We traverse up
into the superproject, and you end up searching a much larger search
space than you want. In the case of my dotfiles repo it's even worse,
because if I am working in ~/.vim/bundle/command-t, ~/.vim is actually a
symlink to ~/code/wincent/.vim; ~/code/wincent/.vim/bundle/command-t is
a submodule of ~/code/wincent, and that gets used as the root. So not
only am I searching for more than I want (including any open files which
will be mirrored as ~/.vim/tmp/swap/some_file.rb.swp etc), the files I
am trying to find are also underneath a dot-directory, so I have to
prefix my searches with a period to get the files to show up.

So, this commit stops traversal at the submodule boundary and doesn't
keep going up to the superproject. In submodules .git will
still exist but in recent versions it will be a normal file containing a
"gitlink"; eg:

    gitdir: ../../../.git/modules/.vim/bundle/command-t

So now we just check for existence rather than directory-ness. This also
means that if you want to ever mark a diretory as a traversal boundary
you can just `touch .git` (or `touch .hg` etc) in it.
  • Loading branch information
wincent committed Aug 15, 2014
1 parent 953aa33 commit 14aad16
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion ruby/command-t/vim/path_utilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def nearest_ancestor(starting_directory, markers)
path = File.expand_path(starting_directory)
while !markers.
map { |dir| File.join(path, dir) }.
map { |dir| File.directory?(dir) }.
map { |dir| File.exist?(dir) }.
any?
return nil if path == '/'
path = File.expand_path(File.join(path, '..'))
Expand Down

0 comments on commit 14aad16

Please sign in to comment.