From 4b2a8c3d72e4298a8143d3414a03822b589cf165 Mon Sep 17 00:00:00 2001 From: Andy Gimblett Date: Mon, 27 Apr 2026 12:19:53 +0000 Subject: [PATCH] fix: support nested scp-style clone URLs try clone accepted git@host:user/repo but rejected valid scp-style SSH URLs with a custom SSH user or deeper repository path, such as user@host:git/prog/repo.git. Parse the generic user@host:path form after the existing git@host:user/repo case, deriving the repository name from the path basename so existing directory naming stays unchanged. --- spec/command_line.md | 3 +++ spec/tests/test_32_git_uri.sh | 8 ++++++++ try.rb | 5 +++++ 3 files changed, 16 insertions(+) diff --git a/spec/command_line.md b/spec/command_line.md index 52066c2..accaf1a 100644 --- a/spec/command_line.md +++ b/spec/command_line.md @@ -77,6 +77,9 @@ try https://github.com/tobi/try.git try clone git@github.com:tobi/try.git # SSH URL also works: 2025-11-30-tobi-try + +try clone deploy@git.example.com:src/team/project.git +# SCP-style SSH URLs with nested paths also work: 2025-11-30-deploy-project ``` ### worktree diff --git a/spec/tests/test_32_git_uri.sh b/spec/tests/test_32_git_uri.sh index 6356928..013a57f 100644 --- a/spec/tests/test_32_git_uri.sh +++ b/spec/tests/test_32_git_uri.sh @@ -36,6 +36,14 @@ else fail "SSH gitlab.com should parse user/repo" "user-sshrepo" "$output" "git_uri" fi +# Test: SCP-style SSH host with custom user and nested path +output=$(try_run --path="$TEST_TRIES" exec clone deploy@git.example.com:src/team/project.git 2>&1) +if echo "$output" | grep -q "deploy-project"; then + pass +else + fail "SCP-style SSH URL should parse nested repo path" "deploy-project" "$output" "git_uri" +fi + # Test: Unparseable URI produces error output=$(try_run --path="$TEST_TRIES" exec clone not-a-valid-uri 2>&1) exit_code=$? diff --git a/try.rb b/try.rb index d966f80..2a97a90 100755 --- a/try.rb +++ b/try.rb @@ -1057,6 +1057,11 @@ def parse_git_uri(uri) # git@host:user/repo host, user, repo = $1, $2, $3 return { user: user, repo: repo, host: host } + elsif uri.match(%r{^([^@/:]+)@([^:]+):(.+)}) + # SCP-style SSH: user@host:path/to/repo + user, host, path = $1, $2, $3 + repo = File.basename(path) + return { user: user, repo: repo, host: host } else return nil end