Repository navigation
feat(get): add --nested option to clone under host/owner/repo layout - #1281
Conversation
Add an opt-in --nested flag to git-get that parses the repository URL (https://host/owner/repo and git@host:owner/repo forms) and clones into <clone-path>/<host>/<owner>/<repo> instead of the flat <clone-path>/<repo-name>. Without the flag, behavior is unchanged. An unparseable URL with --nested produces an error listing supported formats.
| dirname=${dirname##*/} | ||
| parse_repo_url() { | ||
| local url="$1" | ||
| if [[ "$url" =~ ^https?://([^/]+)/(.+?)(/)?$ ]]; then |
There was a problem hiding this comment.
.+? is not supported on MacOS?
There was a problem hiding this comment.
Good eye! I had no idea but it appears you are correct. I changed it so it doesn't rely on lazy quantifiers anymore.
Signed-off-by: Luiz Carvalho <lucarval@redhat.com>
Lazy quantifiers ('.+?') are not supported by bash 3.2, which is still
the default on macOS. Strip trailing slashes from the URL before
matching and use greedy quantifiers instead, which behave identically
and are valid POSIX ERE.
| parse_repo_url() { | ||
| local url="$1" | ||
| url=${url%/} | ||
| if [[ "$url" =~ ^https?://([^/]+)/(.+)$ ]]; then |
There was a problem hiding this comment.
([^/]+) captures the whole authority, including userinfo, so x-access-token:…@host becomes part of the path:
$ git get --nested 'https://x-access-token:SECRETTOKEN@example.com/owner/repo.git'
Cloning into '/home/me/repos/x-access-token:SECRETTOKEN@example.com/owner/repo'...
Better strip userinfo and port.
There was a problem hiding this comment.
I wasn't aware that userinfo could be added to the http(s) URL. This should be fixed.
I also added a doc note about the rare case where a host may serve two git servers at different ports.
| @test "--nested parses https URLs" { | ||
| # The clone itself fails, but the target path shows the parsed layout | ||
| run git get --nested "https://example.com/owner/repo.git" | ||
| assert_output --partial "Cloning into '$clone_path/example.com/owner/repo'" |
There was a problem hiding this comment.
Let's also check the [ -d "$clone_path/origin/.git" ], like the successful cases without --nest.
There was a problem hiding this comment.
Done. I also improved the test by updating the git config so the git clone command actually works.
Signed-off-by: Luiz Carvalho <lucarval@redhat.com>
Signed-off-by: Luiz Carvalho <lucarval@redhat.com>
|
@lcarva |
Add an opt-in --nested flag to git-get that parses the repository URL (https://host/owner/repo and git@host:owner/repo forms) and clones into /// instead of the flat /. Without the flag, behavior is unchanged. An unparseable URL with --nested produces an error listing supported formats.