aboutsummaryrefslogtreecommitdiffstats
path: root/worktree_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'worktree_test.go')
-rw-r--r--worktree_test.go59
1 files changed, 58 insertions, 1 deletions
diff --git a/worktree_test.go b/worktree_test.go
index 59c80af..8a7586a 100644
--- a/worktree_test.go
+++ b/worktree_test.go
@@ -4,6 +4,7 @@ import (
"bytes"
"context"
"errors"
+ "io"
"io/ioutil"
"os"
"path/filepath"
@@ -12,7 +13,7 @@ import (
"testing"
"time"
- fixtures "github.com/go-git/go-git-fixtures/v4"
+ "github.com/go-git/go-git-fixtures/v4"
"github.com/go-git/go-git/v5/config"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/filemode"
@@ -519,6 +520,62 @@ func (s *WorktreeSuite) TestCheckoutSubmoduleInitialized(c *C) {
c.Assert(status.IsClean(), Equals, true)
}
+func (s *WorktreeSuite) TestCheckoutRelativePathSubmoduleInitialized(c *C) {
+ url := "https://github.com/git-fixtures/submodule.git"
+ r := s.NewRepository(fixtures.ByURL(url).One())
+
+ // modify the .gitmodules from original one
+ file, err := r.wt.OpenFile(".gitmodules", os.O_WRONLY|os.O_TRUNC, 0666)
+ c.Assert(err, IsNil)
+
+ n, err := io.WriteString(file, `[submodule "basic"]
+ path = basic
+ url = ../basic.git
+[submodule "itself"]
+ path = itself
+ url = ../submodule.git`)
+ c.Assert(err, IsNil)
+ c.Assert(n, Not(Equals), 0)
+
+ w, err := r.Worktree()
+ c.Assert(err, IsNil)
+
+ w.Add(".gitmodules")
+ w.Commit("test", &CommitOptions{})
+
+ // test submodule path
+ modules, err := w.readGitmodulesFile()
+
+ c.Assert(modules.Submodules["basic"].URL, Equals, "../basic.git")
+ c.Assert(modules.Submodules["itself"].URL, Equals, "../submodule.git")
+
+ basicSubmodule, err := w.Submodule("basic")
+ c.Assert(err, IsNil)
+ basicRepo, err := basicSubmodule.Repository()
+ c.Assert(err, IsNil)
+ basicRemotes, err := basicRepo.Remotes()
+ c.Assert(err, IsNil)
+ c.Assert(basicRemotes[0].Config().URLs[0], Equals, "https://github.com/git-fixtures/basic.git")
+
+ itselfSubmodule, err := w.Submodule("itself")
+ c.Assert(err, IsNil)
+ itselfRepo, err := itselfSubmodule.Repository()
+ c.Assert(err, IsNil)
+ itselfRemotes, err := itselfRepo.Remotes()
+ c.Assert(err, IsNil)
+ c.Assert(itselfRemotes[0].Config().URLs[0], Equals, "https://github.com/git-fixtures/submodule.git")
+
+ sub, err := w.Submodules()
+ c.Assert(err, IsNil)
+
+ err = sub.Update(&SubmoduleUpdateOptions{Init: true, RecurseSubmodules: DefaultSubmoduleRecursionDepth})
+ c.Assert(err, IsNil)
+
+ status, err := w.Status()
+ c.Assert(err, IsNil)
+ c.Assert(status.IsClean(), Equals, true)
+}
+
func (s *WorktreeSuite) TestCheckoutIndexMem(c *C) {
fs := memfs.New()
w := &Worktree{