diff options
| author | Edward Thomson <ethomson@edwardthomson.com> | 2017-03-22 20:32:55 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-03-22 20:32:55 +0000 |
| commit | f623cf894a7e2591e7b4424b24143d1a7584cf9e (patch) | |
| tree | eff28ba6a1a91f51fb71a07969e688fcf1ecc8cd /src/submodule.c | |
| parent | 6fd6c67824d2caad9f8716a676820d8319f79a9d (diff) | |
| parent | b0c9bc920fabfd814946d555738ac7ba042154d7 (diff) | |
| download | libgit2-f623cf894a7e2591e7b4424b24143d1a7584cf9e.tar.gz | |
Merge pull request #4163 from pks-t/pks/submodules-with-worktrees
Worktree fixes
Diffstat (limited to 'src/submodule.c')
| -rw-r--r-- | src/submodule.c | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/submodule.c b/src/submodule.c index 191cdf3dd..ddd4b0663 100644 --- a/src/submodule.c +++ b/src/submodule.c @@ -22,6 +22,7 @@ #include "iterator.h" #include "path.h" #include "index.h" +#include "worktree.h" #define GIT_MODULES_FILE ".gitmodules" @@ -2038,17 +2039,28 @@ static int lookup_default_remote(git_remote **remote, git_repository *repo) static int get_url_base(git_buf *url, git_repository *repo) { int error; + git_worktree *wt = NULL; git_remote *remote = NULL; - if (!(error = lookup_default_remote(&remote, repo))) { + if ((error = lookup_default_remote(&remote, repo)) == 0) { error = git_buf_sets(url, git_remote_url(remote)); - git_remote_free(remote); - } - else if (error == GIT_ENOTFOUND) { - /* if repository does not have a default remote, use workdir instead */ + goto out; + } else if (error != GIT_ENOTFOUND) + goto out; + else giterr_clear(); + + /* if repository does not have a default remote, use workdir instead */ + if (git_repository_is_worktree(repo)) { + if ((error = git_worktree_open_from_repository(&wt, repo)) < 0) + goto out; + error = git_buf_sets(url, wt->parent_path); + } else error = git_buf_sets(url, git_repository_workdir(repo)); - } + +out: + git_remote_free(remote); + git_worktree_free(wt); return error; } |
