Fix "outside repository" error when "git lfs track" in a symlinked dir

This commit is contained in:
Steve Streeting 2015-11-06 09:48:57 +00:00
parent b0318b2535
commit 8af895cfb7
2 changed files with 24 additions and 2 deletions

@ -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 {

@ -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