Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit d87faec

Browse files
committed
1 parent 79b7f24 commit d87faec

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

submodule_test.go

+15
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,21 @@ func (s *SubmoduleSuite) TestSubmodulesInit(c *C) {
196196
}
197197
}
198198

199+
func (s *SubmoduleSuite) TestGitSubmodulesSymlink(c *C) {
200+
f, err := s.Worktree.Filesystem.Create("badfile")
201+
c.Assert(err, IsNil)
202+
defer f.Close()
203+
204+
err = s.Worktree.Filesystem.Remove(gitmodulesFile)
205+
c.Assert(err, IsNil)
206+
207+
err = s.Worktree.Filesystem.Symlink("badfile", gitmodulesFile)
208+
c.Assert(err, IsNil)
209+
210+
_, err = s.Worktree.Submodules()
211+
c.Assert(err, Equals, ErrGitModulesSymlink)
212+
}
213+
199214
func (s *SubmoduleSuite) TestSubmodulesStatus(c *C) {
200215
sm, err := s.Worktree.Submodules()
201216
c.Assert(err, IsNil)

worktree.go

+12
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ var (
2828
ErrWorktreeNotClean = errors.New("worktree is not clean")
2929
ErrSubmoduleNotFound = errors.New("submodule not found")
3030
ErrUnstagedChanges = errors.New("worktree contains unstaged changes")
31+
ErrGitModulesSymlink = errors.New(gitmodulesFile + " is a symlink")
3132
)
3233

3334
// Worktree represents a git worktree.
@@ -680,7 +681,18 @@ func (w *Worktree) newSubmodule(fromModules, fromConfig *config.Submodule) *Subm
680681
return m
681682
}
682683

684+
func (w *Worktree) isSymlink(path string) bool {
685+
if s, err := w.Filesystem.Lstat(path); err == nil {
686+
return s.Mode()&os.ModeSymlink != 0
687+
}
688+
return false
689+
}
690+
683691
func (w *Worktree) readGitmodulesFile() (*config.Modules, error) {
692+
if w.isSymlink(gitmodulesFile) {
693+
return nil, ErrGitModulesSymlink
694+
}
695+
684696
f, err := w.Filesystem.Open(gitmodulesFile)
685697
if err != nil {
686698
if os.IsNotExist(err) {

0 commit comments

Comments
 (0)