Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

guard against invalid remotes passed to git lfs push #974

Merged
merged 2 commits into from
Feb 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions commands/command_pre_push.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"strings"

"github.com/github/git-lfs/git"
"github.com/github/git-lfs/lfs"
"github.com/github/git-lfs/vendor/_nuts/github.com/spf13/cobra"
)
Expand Down Expand Up @@ -48,6 +49,10 @@ func prePushCommand(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]

// We can be passed multiple lines of refs
Expand Down
5 changes: 5 additions & 0 deletions commands/command_push.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions test/test-fetch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 13 additions & 0 deletions test/test-pre-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,16 @@ begin_test "pre-push multiple branches"

)
end_test

begin_test "pre-push with bad remote"
(
set -e

cd repo

echo "refs/heads/master master refs/heads/master 0000000000000000000000000000000000000000" |
git lfs pre-push not-a-remote "$GITSERVER/$reponame" 2>&1 |
tee pre-push.log
grep "Invalid remote name" pre-push.log
)
end_test
9 changes: 9 additions & 0 deletions test/test-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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