libgit2/tests/repo
Josh Triplett a200dc9e1d Fix repository discovery with ceiling_dirs at current directory
git only checks ceiling directories when its search ascends to a parent
directory.  A ceiling directory matching the starting directory will not
prevent git from finding a repository in the starting directory or a
parent directory.  libgit2 handled the former case correctly, but
differed from git in the latter case: given a ceiling directory matching
the starting directory, but no repository at the starting directory,
libgit2 would stop the search at that point rather than finding a
repository in a parent directory.

Test case using git command-line tools:

/tmp$ git init x
Initialized empty Git repository in /tmp/x/.git/
/tmp$ cd x/
/tmp/x$ mkdir subdir
/tmp/x$ cd subdir/
/tmp/x/subdir$ GIT_CEILING_DIRECTORIES=/tmp/x git rev-parse --git-dir
fatal: Not a git repository (or any of the parent directories): .git
/tmp/x/subdir$ GIT_CEILING_DIRECTORIES=/tmp/x/subdir git rev-parse --git-dir
/tmp/x/.git

Fix the testsuite to test this case (in one case fixing a test that
depended on the current behavior), and then fix find_repo to handle this
case correctly.

In the process, simplify and document the logic in find_repo():
- Separate the concepts of "currently checking a .git directory" and
  "number of iterations left before going further counts as a search"
  into two separate variables, in_dot_git and min_iterations.
- Move the logic to handle in_dot_git and append /.git to the top of the
  loop.
- Only search ceiling_dirs and find ceiling_offset after running out of
  min_iterations; since ceiling_offset only tracks the longest matching
  ceiling directory, if ceiling_dirs contained both the current
  directory and a parent directory, this change makes find_repo stop the
  search at the parent directory.
2016-10-01 17:40:40 +02:00
..
config.c Better search path sandboxing 2014-05-15 10:56:28 -07:00
discover.c Fix repository discovery with ceiling_dirs at current directory 2016-10-01 17:40:40 +02:00
getters.c Rename tests-clar to tests 2013-11-14 14:05:52 -08:00
hashfile.c Introduce cl_assert_equal_oid 2014-07-01 14:40:16 -04:00
head.c Add tests for the annotated versions of ref-modifying functions 2015-03-16 16:57:30 +01:00
headtree.c repository: remove log message override for switching the active branch 2015-03-03 14:40:50 +01:00
init.c git_repository_init: include dotfiles when copying templates 2015-12-26 22:41:00 -06:00
iterator.c tests: skip the unreadable file tests as root 2016-04-11 16:05:51 -04:00
message.c Fix some Windows warnings 2014-02-07 15:43:37 -08:00
new.c repository_new: test its bareness 2015-03-10 16:49:24 -04:00
open.c Fix repository discovery with ceiling_dirs at current directory 2016-10-01 17:40:40 +02:00
pathspec.c Fix compile error on Visual Studio 2014-05-27 23:36:07 +09:00
repo_helpers.c Remove the signature from ref-modifying functions 2015-03-03 14:40:50 +01:00
repo_helpers.h Rename tests-clar to tests 2013-11-14 14:05:52 -08:00
reservedname.c repo::reservedname: test a submodule update 2015-09-18 12:17:49 -04:00
setters.c config: borrow refcounted references 2015-03-03 18:35:12 +01:00
shallow.c Improve error propagation in shallow call 2014-02-18 14:05:30 -08:00
state.c repository: distinguish sequencer cherry-pick and revert 2015-11-20 13:19:23 -05:00