@@ -476,6 +476,60 @@ func (s *WorktreeSuite) TestCheckoutSymlink(c *C) {
476476 c .Assert (err , IsNil )
477477}
478478
479+ func TestCheckoutSymlinkArbitraryTarget (t * testing.T ) {
480+ if runtime .GOOS == "windows" {
481+ t .Skip ("git doesn't support symlinks by default in windows" )
482+ }
483+ t .Parallel ()
484+
485+ tests := []struct {
486+ name string
487+ target string
488+ }{
489+ {name : "rel" , target : "target" },
490+ {name : "absolute" , target : "/etc/passwd" },
491+ {name : "dot-dot relative" , target : "../../outside" },
492+ }
493+
494+ for _ , tc := range tests {
495+ t .Run (tc .name , func (t * testing.T ) {
496+ t .Parallel ()
497+
498+ dir := t .TempDir ()
499+ wtFS := osfs .New (dir , osfs .WithBoundOS ())
500+
501+ dotFS , err := wtFS .Chroot (".git" )
502+ require .NoError (t , err )
503+ storage := filesystem .NewStorage (dotFS , cache .NewObjectLRUDefault ())
504+
505+ r , err := Init (storage , wtFS )
506+ require .NoError (t , err )
507+
508+ w , err := r .Worktree ()
509+ require .NoError (t , err )
510+
511+ require .NoError (t , w .Filesystem .Symlink (tc .target , "link" ))
512+ _ , err = w .Add ("link" )
513+ require .NoError (t , err )
514+ _ , err = w .Commit ("add symlink" , & CommitOptions {Author : defaultSignature ()})
515+ require .NoError (t , err )
516+
517+ require .NoError (t , r .Storer .SetIndex (& index.Index {Version : 2 }))
518+ w .Filesystem = newWorktreeFilesystem (
519+ osfs .New (filepath .Join (dir , "worktree-empty" )), true , true )
520+
521+ require .NoError (t , w .Checkout (& CheckoutOptions {}))
522+
523+ _ , err = w .Status ()
524+ require .NoError (t , err )
525+
526+ got , err := w .Filesystem .Readlink ("link" )
527+ require .NoError (t , err )
528+ assert .Equal (t , tc .target , got )
529+ })
530+ }
531+ }
532+
479533func (s * WorktreeSuite ) TestCheckoutSparse (c * C ) {
480534 fs := memfs .New ()
481535 r , err := Clone (memory .NewStorage (), fs , & CloneOptions {
@@ -2124,7 +2178,6 @@ func (s *WorktreeSuite) TestAddFilenameStartingWithDot(c *C) {
21242178 file = status .File ("foo/bar/baz" )
21252179 c .Assert (file .Staging , Equals , Added )
21262180 c .Assert (file .Worktree , Equals , Unmodified )
2127-
21282181}
21292182
21302183func (s * WorktreeSuite ) TestAddGlobErrorNoMatches (c * C ) {
@@ -2492,7 +2545,6 @@ func (s *WorktreeSuite) TestMove(c *C) {
24922545 c .Assert (status , HasLen , 2 )
24932546 c .Assert (status .File ("LICENSE" ).Staging , Equals , Deleted )
24942547 c .Assert (status .File ("foo" ).Staging , Equals , Added )
2495-
24962548}
24972549
24982550func (s * WorktreeSuite ) TestMoveNotExistentEntry (c * C ) {
@@ -3390,7 +3442,6 @@ func (s *WorktreeSuite) TestRestoreBoth(c *C) {
33903442}
33913443
33923444func TestFilePermissions (t * testing.T ) {
3393-
33943445 // Initialize an in memory repository
33953446 remoteUrl := t .TempDir ()
33963447
@@ -3447,5 +3498,4 @@ func TestFilePermissions(t *testing.T) {
34473498 assert .Equal (t , expectedEntry .Name , idx .Entries [i ].Name )
34483499 assert .Equal (t , expectedEntry .Mode , idx .Entries [i ].Mode )
34493500 }
3450-
34513501}
0 commit comments