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

support Suckless as a host #34

Merged
merged 3 commits into from
Oct 27, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions nu-git-manager/git/url.nu
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,33 @@ export def parse-git-url []: string -> record<host: string, owner: string, group
| url parse
| select host path
| update path {
str trim --left --right --char '/'
let tokens = $in
| str trim --left --right --char '/'
| str replace --regex '\/tree\/.*' ''
| path split
| {
owner: ($in | first),
group: ($in | range 1..(-2) | if $in != null { path join | path sanitize }),
repo: ($in | last)
}

let owner = if ($tokens | length) > 1 {
$tokens | first
}

let group = if ($tokens | length) > 1 {
$tokens | range 1..(-2) | if $in != null { path join | path sanitize }
}

{
owner: $owner,
group: $group,
repo: ($tokens | last)
}
}
| flatten
| into record
}

export def get-fetch-push-urls [
repository: record<host: string, owner: string, group: path, repo: string>, # typically from `parse-git-url`
fetch: string, # one of 'https', 'ssh', or empty
push: string, # one of 'https', 'ssh', or empty
fetch: string, # one of 'https', 'ssh', 'git', or empty
push: string, # one of 'https', 'ssh', 'git', or empty
ssh: bool,
]: nothing -> record<fetch: string, push: string> {
let base_url = {
Expand All @@ -37,10 +47,12 @@ export def get-fetch-push-urls [
}
let http_url = $base_url | update scheme "https" | url join
let ssh_url = $base_url | update scheme "ssh" | url join
let git_url = $base_url | update scheme "git" | url join

let fetch_url = match $fetch {
"https" => $http_url,
"ssh" => $ssh_url,
"git" => $git_url,
_ => {
if $ssh {
$ssh_url
Expand All @@ -53,6 +65,7 @@ export def get-fetch-push-urls [
let push_url = match $push {
"https" => $http_url,
"ssh" => $ssh_url,
"git" => $git_url,
_ => {
if $ssh {
$ssh_url
Expand Down
1 change: 1 addition & 0 deletions nu-git-manager/mod.nu
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def "nu-complete git-protocols" []: nothing -> table<value: string, description:

["https", "use the HTTP protocol: will require a PAT authentification for private repositories"],
["ssh", "use the SSH protocol: will require a passphrase unless setup otherwise"],
["git", "use the GIT protocol: useful when cloning a *Suckless* repo"],
]
}

Expand Down
14 changes: 14 additions & 0 deletions tests/mod.nu
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export def git-url-parsing [] {
["https://gitlab.com/foo/bar", "gitlab.com", "foo", null, "bar"],
["git@gitlab.com:foo/bar", "gitlab.com", "foo", null, "bar"],
["git@gitlab.com:foo/bar/baz/brr", "gitlab.com", "foo", "bar/baz", "brr"],
["git://git.suckless.org/st", "git.suckless.org", null, null, "st"],
]

for case in $cases {
Expand All @@ -41,21 +42,34 @@ export def fetch-and-push-urls [] {
[false, "", "", "https", "https"],
[false, "", "ssh", "https", "ssh"],
[false, "", "https", "https", "https"],
[false, "", "git", "https", "git"],
[false, "ssh", "", "ssh", "https"],
[false, "ssh", "ssh", "ssh", "ssh"],
[false, "ssh", "https", "ssh", "https"],
[false, "ssh", "git", "ssh", "git"],
[false, "git", "", "git", "https"],
[false, "git", "ssh", "git", "ssh"],
[false, "git", "https", "git", "https"],
[false, "git", "git", "git", "git"],
[false, "https", "", "https", "https"],
[false, "https", "ssh", "https", "ssh"],
[false, "https", "https", "https", "https"],
[false, "https", "git", "https", "git"],
[true, "", "", "ssh", "ssh"],
[true, "", "ssh", "ssh", "ssh"],
[true, "", "https", "ssh", "https"],
[true, "", "git", "ssh", "git"],
[true, "ssh", "", "ssh", "ssh"],
[true, "ssh", "ssh", "ssh", "ssh"],
[true, "ssh", "https", "ssh", "https"],
[true, "ssh", "git", "ssh", "git"],
[true, "https", "", "https", "ssh"],
[true, "https", "ssh", "https", "ssh"],
[true, "https", "https", "https", "https"],
[true, "git", "", "git", "ssh"],
[true, "git", "ssh", "git", "ssh"],
[true, "git", "https", "git", "https"],
[true, "git", "git", "git", "git"],
]

let repo = {host: "h", owner: "o", group: "", repo: "r"}
Expand Down