Skip to content

feat(get): add --nested option to clone under host/owner/repo layout - #1281

Merged
spacewander merged 5 commits into
tj:mainfrom
lcarva:git-get-nested
Nov 11, 2026
Merged

spacewander merged 5 commits into
tj:mainfrom
lcarva:git-get-nested

Conversation

@lcarva

@lcarva lcarva commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

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.

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.
Comment thread bin/git-get Outdated
dirname=${dirname##*/}
parse_repo_url() {
local url="$1"
if [[ "$url" =~ ^https?://([^/]+)/(.+?)(/)?$ ]]; then

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.+? is not supported on MacOS?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Comment thread bin/git-get
parse_repo_url() {
local url="$1"
url=${url%/}
if [[ "$url" =~ ^https?://([^/]+)/(.+)$ ]]; then

@spacewander spacewander Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

([^/]+) 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread tests/git-get.bats Outdated
@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'"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also check the [ -d "$clone_path/origin/.git" ], like the successful cases without --nest.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@spacewander
spacewander merged commit b0e8222 into tj:main Nov 11, 2026
5 checks passed
@spacewander

Copy link
Copy Markdown
Collaborator

@lcarva
Merged. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants