diff --git a/commands/command_status.go b/commands/command_status.go index 47bec0ca..649574f5 100644 --- a/commands/command_status.go +++ b/commands/command_status.go @@ -22,6 +22,7 @@ var ( func statusCommand(cmd *cobra.Command, args []string) { requireInRepo() + requireWorkingCopy() // tolerate errors getting ref so this works before first commit ref, _ := git.CurrentRef() diff --git a/commands/commands.go b/commands/commands.go index bcffb7bd..e7e351de 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -309,6 +309,22 @@ func requireInRepo() { } } +// requireWorkingCopy requires that the working directory be a work tree, i.e., +// that it not be bare. If it is bare (or the state of the repository could not +// be determined), this function will terminate the program. +func requireWorkingCopy() { + bare, err := git.IsBare() + if err != nil { + ExitWithError(errors.Wrap( + err, "fatal: could not determine bareness")) + } + + if bare { + Print("This operation must be run in a work tree.") + os.Exit(128) + } +} + func handlePanic(err error) string { if err == nil { return "" diff --git a/docs/man/git-lfs-status.1.ronn b/docs/man/git-lfs-status.1.ronn index 4fe533db..8a37e723 100644 --- a/docs/man/git-lfs-status.1.ronn +++ b/docs/man/git-lfs-status.1.ronn @@ -18,6 +18,8 @@ Display paths of Git LFS objects that * have differences between the working tree and the index file. These are files that could be staged using `git add`. +This command must be run in a non-bare repository. + ## OPTIONS * `--porcelain`: diff --git a/t/t-status.sh b/t/t-status.sh index 0ce4c546..b55194b3 100755 --- a/t/t-status.sh +++ b/t/t-status.sh @@ -448,3 +448,19 @@ Git LFS objects not staged for commit:" [ "$expected" = "$(git lfs status)" ] ) end_test + +begin_test "status (without a working copy)" +( + reponame="status-no-working-copy.git" + + git init --bare "$reponame" + cd "$reponame" + + git lfs status 2>&1 | tee status.log + if [ "0" -eq "${PIPESTATUS[0]}" ]; then + echo >&2 "git lfs status should have failed, didn't ..." + exit 1 + fi + [ "This operation must be run in a work tree." = "$(cat status.log)" ] +) +end_test