wrap the common behavior in requireInRepo()

This commit is contained in:
rick 2015-09-08 10:23:27 -06:00
parent 4174867802
commit 416eb2880c
7 changed files with 14 additions and 31 deletions

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

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

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

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

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

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

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