diff options
| author | Josh Triplett <josh@joshtriplett.org> | 2016-04-03 16:01:01 -0700 |
|---|---|---|
| committer | Josh Triplett <josh@joshtriplett.org> | 2016-06-24 11:44:01 -0700 |
| commit | 39c6fca33aa38ad26c7c5f36734c6434593daae1 (patch) | |
| tree | b6782904f4276033c62dc1b2bb12035c51816153 /src | |
| parent | ed577134a5dcf30c95b740859aceebd9c1137157 (diff) | |
| download | libgit2-39c6fca33aa38ad26c7c5f36734c6434593daae1.tar.gz | |
Add GIT_REPOSITORY_OPEN_NO_DOTGIT flag to avoid appending /.git
GIT_REPOSITORY_OPEN_NO_SEARCH does not search up through parent
directories, but still tries the specified path both directly and with
/.git appended. GIT_REPOSITORY_OPEN_BARE avoids appending /.git, but
opens the repository in bare mode even if it has a working directory.
To support the semantics git uses when given $GIT_DIR in the
environment, provide a new GIT_REPOSITORY_OPEN_NO_DOTGIT flag to not try
appending /.git.
Diffstat (limited to 'src')
| -rw-r--r-- | src/repository.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/repository.c b/src/repository.c index 3ea15b790..5b4346793 100644 --- a/src/repository.c +++ b/src/repository.c @@ -370,11 +370,12 @@ static int find_repo( /* in_dot_git toggles each loop: * /a/b/c/.git, /a/b/c, /a/b/.git, /a/b, /a/.git, /a - * With GIT_REPOSITORY_OPEN_BARE, we assume we started with /a/b/c.git - * and don't append .git the first time through. + * With GIT_REPOSITORY_OPEN_BARE or GIT_REPOSITORY_OPEN_NO_DOTGIT, we + * assume we started with /a/b/c.git and don't append .git the first + * time through. * min_iterations indicates the number of iterations left before going * further counts as a search. */ - if (flags & GIT_REPOSITORY_OPEN_BARE) { + if (flags & (GIT_REPOSITORY_OPEN_BARE | GIT_REPOSITORY_OPEN_NO_DOTGIT)) { in_dot_git = true; min_iterations = 1; } else { @@ -384,10 +385,12 @@ static int find_repo( while (!error && (min_iterations || !(path.ptr[ceiling_offset] == 0 || (flags & GIT_REPOSITORY_OPEN_NO_SEARCH)))) { - if (!in_dot_git) - if ((error = git_buf_joinpath(&path, path.ptr, DOT_GIT)) < 0) - break; - in_dot_git = !in_dot_git; + if (!(flags & GIT_REPOSITORY_OPEN_NO_DOTGIT)) { + if (!in_dot_git) + if ((error = git_buf_joinpath(&path, path.ptr, DOT_GIT)) < 0) + break; + in_dot_git = !in_dot_git; + } if (p_stat(path.ptr, &st) == 0) { /* check that we have not crossed device boundaries */ |
