diff options
author | Axel Christ <axel.christ@inovex.de> | 2020-10-28 16:52:52 +0100 |
---|---|---|
committer | Axel Christ <axel.christ@inovex.de> | 2020-10-28 17:05:05 +0100 |
commit | 81d429bc0f13d05770fa5a824202e07f6f80c001 (patch) | |
tree | 93e5f22e678d9d417f89d8fe0d9b4d15a699a298 /worktree.go | |
parent | 15aedd2ff43c25e0d54d6b488114725a266c79d0 (diff) | |
download | go-git-81d429bc0f13d05770fa5a824202e07f6f80c001.tar.gz |
Fix relative submodule resolution
With the current behavior, the config will always hold the resolved,
absolute URL, leavin the user of go-git no choice to determine whether
the original URL is relative or not.
This changes to employ relative URL resolution only when resolving
a submodule to a repository to keep the correct configuration
'unresolved' and intact.
Change relative resolution using `filepath.Dir` to `path.Join` while
parsing both the 'root' and the relative URL with `net/url.URL`.
Adapt test to verify the new behavior.
Re-fixes #184 (see comments).
Diffstat (limited to 'worktree.go')
-rw-r--r-- | worktree.go | 22 |
1 files changed, 0 insertions, 22 deletions
diff --git a/worktree.go b/worktree.go index c79e715..1c89a02 100644 --- a/worktree.go +++ b/worktree.go @@ -720,31 +720,9 @@ func (w *Worktree) readGitmodulesFile() (*config.Modules, error) { return m, err } - w.resolveRelativeSubmodulePaths(m) - return m, nil } - -// resolveRelativeSubmodulePaths is to replace any relative submodule URL (../foobar.git) in .gitmodules -// to the accessible repository URL -func (w *Worktree) resolveRelativeSubmodulePaths(m *config.Modules) { - origin, err := w.r.Remotes() - // remote is not associated with this worktree. we don't need to process any futher more - if err != nil { - return - } - - parentURL := filepath.Dir(origin[0].c.URLs[0]) - - for i := range m.Submodules { - if strings.HasPrefix(m.Submodules[i].URL, "../") { - child := strings.Replace(m.Submodules[i].URL, "../", "", 1) - m.Submodules[i].URL = fmt.Sprintf("%s/%s", parentURL, child) - } - } -} - // Clean the worktree by removing untracked files. // An empty dir could be removed - this is what `git clean -f -d .` does. func (w *Worktree) Clean(opts *CleanOptions) error { |