diff --git a/commands/command_checkout.go b/commands/command_checkout.go index 3a560f99..1aa1ba49 100644 --- a/commands/command_checkout.go +++ b/commands/command_checkout.go @@ -21,10 +21,7 @@ var ( ) func checkoutCommand(cmd *cobra.Command, args []string) { - if !lfs.InRepo() { - Print("Not in a git repository.") - os.Exit(128) - } + requireInRepo() // Parameters are filters // firstly convert any pathspecs to the root of the repo, in case this is being executed in a sub-folder diff --git a/commands/command_fetch.go b/commands/command_fetch.go index 63c7a5e0..9bdf2963 100644 --- a/commands/command_fetch.go +++ b/commands/command_fetch.go @@ -2,7 +2,6 @@ package commands import ( "fmt" - "os" "time" "github.com/github/git-lfs/git" @@ -24,12 +23,9 @@ var ( ) func fetchCommand(cmd *cobra.Command, args []string) { - var refs []*git.Ref + requireInRepo() - if !lfs.InRepo() { - Print("Not in a git repository.") - os.Exit(128) - } + var refs []*git.Ref if len(args) > 0 { // Remote is first arg diff --git a/commands/command_fsck.go b/commands/command_fsck.go index 1d500409..d87bf1ca 100644 --- a/commands/command_fsck.go +++ b/commands/command_fsck.go @@ -23,10 +23,7 @@ var ( ) func doFsck() (bool, error) { - if !lfs.InRepo() { - Print("Not in a git repository.") - os.Exit(128) - } + requireInRepo() ref, err := git.CurrentRef() if err != nil { diff --git a/commands/command_ls_files.go b/commands/command_ls_files.go index afe68e73..8118e486 100644 --- a/commands/command_ls_files.go +++ b/commands/command_ls_files.go @@ -1,8 +1,6 @@ package commands import ( - "os" - "github.com/github/git-lfs/git" "github.com/github/git-lfs/lfs" "github.com/github/git-lfs/vendor/_nuts/github.com/spf13/cobra" @@ -17,10 +15,7 @@ var ( ) func lsFilesCommand(cmd *cobra.Command, args []string) { - if !lfs.InRepo() { - Print("Not in a git repository.") - os.Exit(128) - } + requireInRepo() var ref string var err error diff --git a/commands/command_pull.go b/commands/command_pull.go index 2bd46eff..348aef51 100644 --- a/commands/command_pull.go +++ b/commands/command_pull.go @@ -1,8 +1,6 @@ package commands import ( - "os" - "github.com/github/git-lfs/git" "github.com/github/git-lfs/lfs" "github.com/github/git-lfs/vendor/_nuts/github.com/spf13/cobra" @@ -19,10 +17,7 @@ var ( ) func pullCommand(cmd *cobra.Command, args []string) { - if !lfs.InRepo() { - Print("Not in a git repository.") - os.Exit(128) - } + requireInRepo() if len(args) > 0 { // Remote is first arg diff --git a/commands/command_status.go b/commands/command_status.go index 9991740b..8ad2d196 100644 --- a/commands/command_status.go +++ b/commands/command_status.go @@ -2,7 +2,6 @@ package commands import ( "fmt" - "os" "github.com/github/git-lfs/git" "github.com/github/git-lfs/lfs" @@ -19,10 +18,7 @@ var ( ) func statusCommand(cmd *cobra.Command, args []string) { - if !lfs.InRepo() { - Print("Not in a git repository.") - os.Exit(128) - } + requireInRepo() ref, err := git.CurrentRef() if err != nil { diff --git a/commands/commands.go b/commands/commands.go index ce1a90b3..2a4a3c4d 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -105,6 +105,13 @@ func requireStdin(msg string) { } } +func requireInRepo() { + if !lfs.InRepo() { + Print("Not in a git repository.") + os.Exit(128) + } +} + func handlePanic(err error) string { if err == nil { return ""