diff --git a/commands/command_track.go b/commands/command_track.go index c10eeae5..e9c587d2 100644 --- a/commands/command_track.go +++ b/commands/command_track.go @@ -62,8 +62,13 @@ ArgsLoop: absT, relT := absRelPath(t, wd) if !filepath.HasPrefix(absT, lfs.LocalWorkingDir) { - Print("%s is outside repository", t) - os.Exit(128) + // check symlinks; LocalWorkingDir has symlinks resolved by rev-parse + // have to resolve dir without track pattern + actualDirT, err := filepath.EvalSymlinks(filepath.Dir(absT)) + if err != nil || !filepath.HasPrefix(actualDirT, lfs.LocalWorkingDir) { + Print("%s is outside repository", t) + os.Exit(128) + } } for _, k := range knownPaths { diff --git a/test/test-track.sh b/test/test-track.sh index 4d3c8d28..9d715a7b 100755 --- a/test/test-track.sh +++ b/test/test-track.sh @@ -215,3 +215,20 @@ begin_test "track in gitDir" exit 1 ) end_test + +begin_test "track in symlinked dir" +( + set -e + + git init track-symlinkdst + ln -s track-symlinkdst track-symlinksrc + cd track-symlinksrc + + git lfs track "*.png" + grep "^*.png" .gitattributes || { + echo ".gitattributes doesn't contain the expected relative path *.png:" + cat .gitattributes + exit 1 + } +) +end_test