diff --git a/commands/command_push.go b/commands/command_push.go index 044328e5..90dab464 100644 --- a/commands/command_push.go +++ b/commands/command_push.go @@ -4,6 +4,7 @@ import ( "io/ioutil" "os" + "github.com/github/git-lfs/git" "github.com/github/git-lfs/lfs" "github.com/github/git-lfs/vendor/_nuts/github.com/rubyist/tracerx" "github.com/github/git-lfs/vendor/_nuts/github.com/spf13/cobra" @@ -159,6 +160,10 @@ func pushCommand(cmd *cobra.Command, args []string) { os.Exit(1) } + // Remote is first arg + if err := git.ValidateRemote(args[0]); err != nil { + Exit("Invalid remote name %q", args[0]) + } lfs.Config.CurrentRemote = args[0] if useStdin { diff --git a/test/test-fetch.sh b/test/test-fetch.sh index 346d2400..d1258433 100755 --- a/test/test-fetch.sh +++ b/test/test-fetch.sh @@ -538,3 +538,12 @@ begin_test "fetch --prune" refute_local_object "$oid_commit2" ) end_test + +begin_test "fetch with invalid remote" +( + set -e + cd repo + git lfs fetch not-a-remote 2>&1 | tee fetch.log + grep "Invalid remote name" fetch.log +) +end_test diff --git a/test/test-push.sh b/test/test-push.sh index ef54c3de..d30f9727 100755 --- a/test/test-push.sh +++ b/test/test-push.sh @@ -410,3 +410,12 @@ begin_test "push modified files" assert_server_object "$reponame" "$oid5" ) end_test + +begin_test "push with invalid remote" +( + set -e + cd repo + git lfs push not-a-remote 2>&1 | tee push.log + grep "Invalid remote name" push.log +) +end_test