This repository was archived by the owner on Sep 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 534
This repository was archived by the owner on Sep 11, 2020. It is now read-only.
Support for relative URL of submodule URL #737
Copy link
Copy link
Open
Labels
Description
Problem
Git allows relative URL in .gitmodules
.
Here is an example.
[submodule "child"]
path = child
url = ../submodule-test-child
The relative URL allows to specify submodule repository regardless of scheme (ssh, https).
$ git clone --recursive git@github.com:tyru/submodule-test.git ssh-test
$ (cd ssh-test/child && git remote -v)
origin git@github.com:tyru/submodule-test-child (fetch)
origin git@github.com:tyru/submodule-test-child (push)
$ git clone --recursive https://github.com/tyru/submodule-test https-test
$ (cd https-test/child && git remote -v)
origin https://github.com/tyru/submodule-test-child (fetch)
origin https://github.com/tyru/submodule-test-child (push)
What I did
$ go run clone-repo.go https://github.com/tyru/submodule-test submodule-test
clone-repo.go
func main() {
url, directory := os.Args[1], os.Args[2]
_, err := git.PlainClone(directory, false, &git.CloneOptions{
URL: url,
RecurseSubmodules: git.DefaultSubmoduleRecursionDepth,
Progress: os.Stdout,
})
if err != nil {
panic(err)
}
}
What I got
Counting objects: 9, done.
Compressing objects: 100% (6/6), done.
Total 9 (delta 0), reused 3 (delta 0), pack-reused 0
panic: repository not found
goroutine 1 [running]:
main.main()
/home/tyru/.gvm/pkgsets/go1.10beta1/global/src/go-git-clone/clone-repo.go:20 +0x22c
exit status 2
What I expected
git.PlainClone()
succeeds with no error.- submodule repository "submodule-test/child" was cloned
Note
I don't know which behavior is better though, but I found a difference when gitlink does not exist but .gitmodules has the entry for the path.
git
command seems to ignore error.
$ git clone --recursive git@github.com:tyru/submodule-test2.git
$ echo $?
0
$ cd submodule-test2
$ git ls-files
.gitmodules
README.md
$ cat .gitmodules
[submodule "child"]
path = child
url = ../submodule-test-child
go-git reports an error.
$ go run clone-repo.go https://github.com/tyru/submodule-test2 test2
Counting objects: 8, done.
Compressing objects: 100% (6/6), done.
Total 8 (delta 1), reused 5 (delta 1), pack-reused 0
panic: entry not found
goroutine 1 [running]:
main.main()
/home/tyru/.gvm/pkgsets/go1.10beta1/global/src/go-git-clone/clone-repo.go:17 +0x12d
exit status 2