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

feat: Remember HTTP username in URL in init command #2562

Merged
merged 1 commit into from
Nov 11, 2022
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
14 changes: 7 additions & 7 deletions assets/chezmoi.io/docs/reference/commands/init.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ By default, if *repo* is given, chezmoi will guess the full git repo URL, using
HTTPS by default, or SSH if the `--ssh` option is specified, according to the
following patterns:

| Pattern | HTTPS Repo | SSH repo |
| ------------------ | -------------------------------------- | ---------------------------------- |
| `user` | `https://github.com/user/dotfiles.git` | `git@github.com:user/dotfiles.git` |
| `user/repo` | `https://github.com/user/repo.git` | `git@github.com:user/repo.git` |
| `site/user/repo` | `https://site/user/repo.git` | `git@site:user/repo.git` |
| `sr.ht/~user` | `https://git.sr.ht/~user/dotfiles` | `git@git.sr.ht:~user/dotfiles.git` |
| `sr.ht/~user/repo` | `https://git.sr.ht/~user/repo` | `git@git.sr.ht:~user/repo.git` |
| Pattern | HTTPS Repo | SSH repo |
| ------------------ | ------------------------------------------- | ---------------------------------- |
| `user` | `https://user@github.com/user/dotfiles.git` | `git@github.com:user/dotfiles.git` |
| `user/repo` | `https://user@github.com/user/repo.git` | `git@github.com:user/repo.git` |
| `site/user/repo` | `https://user@site/user/repo.git` | `git@site:user/repo.git` |
| `sr.ht/~user` | `https://user@git.sr.ht/~user/dotfiles` | `git@git.sr.ht:~user/dotfiles.git` |
| `sr.ht/~user/repo` | `https://user@git.sr.ht/~user/repo` | `git@git.sr.ht:~user/repo.git` |

To disable git repo URL guessing pass the `--guess-repo-url=false` option.

Expand Down
16 changes: 8 additions & 8 deletions pkg/cmd/initcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,49 +45,49 @@ var dotfilesRepoGuesses = []struct {
}{
{
rx: regexp.MustCompile(`\A([-0-9A-Za-z]+)\z`),
httpRepoGuessRepl: "https://github.com/$1/dotfiles.git",
httpRepoGuessRepl: "https://$1@github.com/$1/dotfiles.git",
httpUsernameGuessRepl: "$1",
sshRepoGuessRepl: "git@github.com:$1/dotfiles.git",
},
{
rx: regexp.MustCompile(`\A([-0-9A-Za-z]+)/([-0-9A-Za-z]+)(\.git)?\z`),
httpRepoGuessRepl: "https://github.com/$1/$2.git",
httpRepoGuessRepl: "https://$1@github.com/$1/$2.git",
httpUsernameGuessRepl: "$1",
sshRepoGuessRepl: "git@github.com:$1/$2.git",
},
{
rx: regexp.MustCompile(`\A([-.0-9A-Za-z]+)/([-0-9A-Za-z]+)\z`),
httpRepoGuessRepl: "https://$1/$2/dotfiles.git",
httpRepoGuessRepl: "https://$2@$1/$2/dotfiles.git",
httpUsernameGuessRepl: "$2",
sshRepoGuessRepl: "git@$1:$2/dotfiles.git",
},
{
rx: regexp.MustCompile(`\A([-0-9A-Za-z]+)/([-0-9A-Za-z]+)/([-.0-9A-Za-z]+)\z`),
httpRepoGuessRepl: "https://$1/$2/$3.git",
httpRepoGuessRepl: "https://$2@$1/$2/$3.git",
httpUsernameGuessRepl: "$2",
sshRepoGuessRepl: "git@$1:$2/$3.git",
},
{
rx: regexp.MustCompile(`\A([-.0-9A-Za-z]+)/([-0-9A-Za-z]+)/([-0-9A-Za-z]+)(\.git)?\z`),
httpRepoGuessRepl: "https://$1/$2/$3.git",
httpRepoGuessRepl: "https://$2@$1/$2/$3.git",
httpUsernameGuessRepl: "$2",
sshRepoGuessRepl: "git@$1:$2/$3.git",
},
{
rx: regexp.MustCompile(`\A(https?://)([-.0-9A-Za-z]+)/([-0-9A-Za-z]+)/([-0-9A-Za-z]+)(\.git)?\z`),
httpRepoGuessRepl: "$1$2/$3/$4.git",
httpRepoGuessRepl: "$1$3@$2/$3/$4.git",
httpUsernameGuessRepl: "$3",
sshRepoGuessRepl: "git@$2:$3/$4.git",
},
{
rx: regexp.MustCompile(`\Asr\.ht/~([-0-9A-Za-z]+)\z`),
httpRepoGuessRepl: "https://git.sr.ht/~$1/dotfiles",
httpRepoGuessRepl: "https://$1@git.sr.ht/~$1/dotfiles",
httpUsernameGuessRepl: "$1",
sshRepoGuessRepl: "git@git.sr.ht:~$1/dotfiles",
},
{
rx: regexp.MustCompile(`\Asr\.ht/~([-0-9A-Za-z]+)/([-0-9A-Za-z]+)\z`),
httpRepoGuessRepl: "https://git.sr.ht/~$1/$2",
httpRepoGuessRepl: "https://$1@git.sr.ht/~$1/$2",
httpUsernameGuessRepl: "$1",
sshRepoGuessRepl: "git@git.sr.ht:~$1/$2",
},
Expand Down
24 changes: 12 additions & 12 deletions pkg/cmd/initcmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,73 +26,73 @@ func TestGuessDotfilesRepoURL(t *testing.T) {
},
{
arg: "codeberg.org/user",
expectedHTTPRepoURL: "https://codeberg.org/user/dotfiles.git",
expectedHTTPRepoURL: "https://user@codeberg.org/user/dotfiles.git",
expectedHTTPUsername: "user",
expectedSSHRepoURL: "git@codeberg.org:user/dotfiles.git",
},
{
arg: "codeberg.org/user/dots",
expectedHTTPRepoURL: "https://codeberg.org/user/dots.git",
expectedHTTPRepoURL: "https://user@codeberg.org/user/dots.git",
expectedHTTPUsername: "user",
expectedSSHRepoURL: "git@codeberg.org:user/dots.git",
},
{
arg: "gitlab.com/user",
expectedHTTPRepoURL: "https://gitlab.com/user/dotfiles.git",
expectedHTTPRepoURL: "https://user@gitlab.com/user/dotfiles.git",
expectedHTTPUsername: "user",
expectedSSHRepoURL: "git@gitlab.com:user/dotfiles.git",
},
{
arg: "gitlab.com/user/dots",
expectedHTTPRepoURL: "https://gitlab.com/user/dots.git",
expectedHTTPRepoURL: "https://user@gitlab.com/user/dots.git",
expectedHTTPUsername: "user",
expectedSSHRepoURL: "git@gitlab.com:user/dots.git",
},
{
arg: "gitlab.com/user/dots.git",
expectedHTTPRepoURL: "https://gitlab.com/user/dots.git",
expectedHTTPRepoURL: "https://user@gitlab.com/user/dots.git",
expectedHTTPUsername: "user",
expectedSSHRepoURL: "git@gitlab.com:user/dots.git",
},
{
arg: "http://gitlab.com/user/dots.git",
expectedHTTPRepoURL: "http://gitlab.com/user/dots.git",
expectedHTTPRepoURL: "http://user@gitlab.com/user/dots.git",
expectedHTTPUsername: "user",
expectedSSHRepoURL: "git@gitlab.com:user/dots.git",
},
{
arg: "https://gitlab.com/user/dots.git",
expectedHTTPRepoURL: "https://gitlab.com/user/dots.git",
expectedHTTPRepoURL: "https://user@gitlab.com/user/dots.git",
expectedHTTPUsername: "user",
expectedSSHRepoURL: "git@gitlab.com:user/dots.git",
},
{
arg: "sr.ht/~user",
expectedHTTPRepoURL: "https://git.sr.ht/~user/dotfiles",
expectedHTTPRepoURL: "https://user@git.sr.ht/~user/dotfiles",
expectedHTTPUsername: "user",
expectedSSHRepoURL: "git@git.sr.ht:~user/dotfiles",
},
{
arg: "sr.ht/~user/dots",
expectedHTTPRepoURL: "https://git.sr.ht/~user/dots",
expectedHTTPRepoURL: "https://user@git.sr.ht/~user/dots",
expectedHTTPUsername: "user",
expectedSSHRepoURL: "git@git.sr.ht:~user/dots",
},
{
arg: "user",
expectedHTTPRepoURL: "https://github.com/user/dotfiles.git",
expectedHTTPRepoURL: "https://user@github.com/user/dotfiles.git",
expectedHTTPUsername: "user",
expectedSSHRepoURL: "git@github.com:user/dotfiles.git",
},
{
arg: "user/dots",
expectedHTTPRepoURL: "https://github.com/user/dots.git",
expectedHTTPRepoURL: "https://user@github.com/user/dots.git",
expectedHTTPUsername: "user",
expectedSSHRepoURL: "git@github.com:user/dots.git",
},
{
arg: "user/dots.git",
expectedHTTPRepoURL: "https://github.com/user/dots.git",
expectedHTTPRepoURL: "https://user@github.com/user/dots.git",
expectedHTTPUsername: "user",
expectedSSHRepoURL: "git@github.com:user/dots.git",
},
Expand Down