diff --git a/commands/command_track.go b/commands/command_track.go index ba3a53cf..e6d8a98b 100644 --- a/commands/command_track.go +++ b/commands/command_track.go @@ -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() diff --git a/lfs/lfs.go b/lfs/lfs.go index d136cb3b..31e4ab41 100644 --- a/lfs/lfs.go +++ b/lfs/lfs.go @@ -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) diff --git a/test/test-submodule.sh b/test/test-submodule.sh index c242240e..de85911b 100755 --- a/test/test-submodule.sh +++ b/test/test-submodule.sh @@ -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