Skip to content

Commit

Permalink
support ls-remote, and git+ssh protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
jakecoffman committed May 12, 2023
1 parent af162fe commit 7a908bd
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,10 @@ jobs:

- name: Test
run: go test -v ./...

integration-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Integration test
run: docker build -f test/Dockerfile .
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
git
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func main() {
}
}

var allowedCommands = []string{"clone", "fetch"}
var allowedCommands = []string{"clone", "fetch", "ls-remote"}

// IsRewriteAllowed returns true if it is safe to rewrite arguments. Some commands
// such as config would break if rewritten, like when using insteadOf.
Expand Down Expand Up @@ -89,7 +89,7 @@ func FindGit(envPath string) string {
}

var scpUrl = regexp.MustCompile(`^(?P<user>\S+?)@(?P<host>[a-zA-Z\d-]+(\.[a-zA-Z\d-]+)+\.?):(?P<path>.*?/.*?)$`)
var allowedSchemes = []string{"git", "ssh"}
var allowedSchemes = []string{"git", "ssh", "git+ssh"}

// Scrub rewrites arguments that look like URLs to have the HTTPS protocol.
func Scrub(argument string) string {
Expand Down
12 changes: 12 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ func TestIsRewriteAllowed(t *testing.T) {
input: []string{"fetch", ""},
expected: true,
},
{
input: []string{"ls-remote", ""},
expected: true,
},
{
input: []string{"--work-tree=/work", "clone"},
expected: true,
Expand Down Expand Up @@ -51,6 +55,14 @@ func TestScrub(t *testing.T) {
input: "[email protected]:dependabot/git-https-shim",
expected: "https://github.com/dependabot/git-https-shim",
},
{
input: "git+ssh://[email protected]/dependabot/git-https-shim",
expected: "https://github.com/dependabot/git-https-shim",
},
{
input: "git+ssh://user:[email protected]/dependabot/git-https-shim",
expected: "https://user:[email protected]/dependabot/git-https-shim",
},
{
input: "ssh://user:[email protected]/dependabot/git-https-shim",
expected: "https://user:[email protected]/dependabot/git-https-shim",
Expand Down

0 comments on commit 7a908bd

Please sign in to comment.