Allowed track only if we're in a working dir

See `git add`; Exit status and message are taken from there.

Fixes github/git-lfs#353
This commit is contained in:
Michael Käufl 2015-05-30 14:32:10 +02:00
parent 73d54e1f68
commit 233b4c717b
3 changed files with 7 additions and 2 deletions

@ -25,6 +25,10 @@ func trackCommand(cmd *cobra.Command, args []string) {
Print("Not a git repository.")
os.Exit(128)
}
if lfs.LocalWorkingDir == "" {
Print("This operation must be run in a work tree.")
os.Exit(128)
}
lfs.InstallHooks(false)
knownPaths := findPaths()

@ -128,7 +128,8 @@ func recursiveResolveGitDir(dir string) (string, string, error) {
}
if filepath.Base(dir) == gitExt {
return filepath.Dir(dir), dir, nil
// We're in the `.git` directory. Make no assumptions about the working directory.
return "", dir, nil
}
gitDir := filepath.Join(dir, gitExt)

@ -51,7 +51,7 @@ begin_test "submodule env"
echo "./.git"
git lfs env | tee env.log
grep "Endpoint=$GITSERVER/$reponame.git/info/lfs$" env.log
grep "LocalWorkingDir=$TRASHDIR/repo$" env.log
grep "LocalWorkingDir=$" env.log
grep "LocalGitDir=$TRASHDIR/repo/.git$" env.log
grep "LocalMediaDir=$TRASHDIR/repo/.git/lfs/objects$" env.log
grep "TempDir=$TRASHDIR/repo/.git/lfs/tmp$" env.log