[PATCH v7 4/7] submodule: allow do_submodule_path to work if given gitdir directly
- From
Jacob Keller <jacob.e.keller@intel.com>
- Date
- Aug 18, 2016, 00:51 UTC
- Message-ID
- <20160818005131.31600-5-jacob.e.keller@intel.com>
- In-Reply-To
- <20160818005131.31600-1-jacob.e.keller@intel.com>
From: Jacob Keller <jacob.keller@gmail.com>
Currently, do_submodule_path relies on read_gitfile, which will die() if it can't read from the specified gitfile. Unfortunately, this means that do_submodule_path will not work when given the path to a submodule which is checked out directly, such as a newly added submodule which you cloned and then "git submodule add". Instead, replace the call with resolve_gitdir. This first checks to see if we've been given a gitdir already.
Because resolve_gitdir may return the same buffer it was passed, we have to check for this case as well, since strbuf_reset() will not work as expected here, and indeed is not necessary.
Signed-off-by: Jacob Keller <jacob.keller@gmail.com> --- path.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/path.c b/path.c index 17551c483476..d1af029152a2 100644 --- a/path.c +++ b/path.c @@ -477,8 +477,8 @@ static void do_submodule_path(struct strbuf *buf, const char *path, strbuf_complete(buf, '/'); strbuf_addstr(buf, ".git"); - git_dir = read_gitfile(buf->buf); - if (git_dir) { + git_dir = resolve_gitdir(buf->buf); + if (git_dir && git_dir != buf->buf) { strbuf_reset(buf); strbuf_addstr(buf, git_dir); }
-- 2.10.0.rc0.217.g609f9e8.dirty