add agentws prune
Agents leave their managed worktrees behind, and `agentws rm` takes one path at a time with no idea whether a branch's work is safely upstream, so clearing an accumulation by hand risks destroying unmerged commits. - classify every managed worktree: dirty, PR open, upstream, or unproven - remove only what is safe; delete the local branch only when work is upstream - prove "upstream" with merge-base and git cherry, so squash merges count - match a PR by head.label, which survives the branch deletion a merge does - dry run by default; --yes applies, --keep-branches spares every branch - read the Gitea path from origin's URL rather than assuming the owner
This commit is contained in:
@@ -132,3 +132,52 @@ func TestParseDurationFlagErrorMessage(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Not every managed repo lives under the default owner, so the API path comes
|
||||
// from origin's URL rather than the directory name.
|
||||
func TestRepoPathFromRemoteURL(t *testing.T) {
|
||||
tests := []struct {
|
||||
in string
|
||||
want string
|
||||
}{
|
||||
{"https://git.unkin.net/unkin/agent-tools.git", "unkin/agent-tools"},
|
||||
{"https://git.unkin.net/unkinben/dotfiles.git", "unkinben/dotfiles"},
|
||||
{"https://git.unkin.net/unkin/agent-tools", "unkin/agent-tools"},
|
||||
{"https://user@git.unkin.net/unkin/agent-tools.git", "unkin/agent-tools"},
|
||||
{"ssh://git@git.unkin.net:2222/unkin/agent-tools.git", "unkin/agent-tools"},
|
||||
{"git@git.unkin.net:unkin/agent-tools.git", "unkin/agent-tools"},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
got, err := RepoPathFromRemoteURL(tt.in)
|
||||
if err != nil {
|
||||
t.Errorf("RepoPathFromRemoteURL(%q): %v", tt.in, err)
|
||||
continue
|
||||
}
|
||||
if got != tt.want {
|
||||
t.Errorf("RepoPathFromRemoteURL(%q) = %q, want %q", tt.in, got, tt.want)
|
||||
}
|
||||
}
|
||||
for _, bad := range []string{"", "https://git.unkin.net", "agent-tools"} {
|
||||
if got, err := RepoPathFromRemoteURL(bad); err == nil {
|
||||
t.Errorf("RepoPathFromRemoteURL(%q) = %q, want error", bad, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoteHost(t *testing.T) {
|
||||
tests := []struct {
|
||||
in, want string
|
||||
}{
|
||||
{"https://git.unkin.net/unkin/repo.git", "git.unkin.net"},
|
||||
{"https://user@git.unkin.net/unkin/repo.git", "git.unkin.net"},
|
||||
{"ssh://git@git.unkin.net:2222/unkin/repo.git", "git.unkin.net:2222"},
|
||||
{"git@git.unkin.net:unkin/repo.git", "git.unkin.net"},
|
||||
{"/tmp/fixture/origin.git", ""},
|
||||
{"../other/origin.git", ""},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
if got := RemoteHost(tt.in); got != tt.want {
|
||||
t.Errorf("RemoteHost(%q) = %q, want %q", tt.in, got, tt.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user