Skip to content
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
16 changes: 15 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"bytes"
"fmt"
"os"
"os/exec"
Expand Down Expand Up @@ -663,7 +664,20 @@ func cmdPurge(_ []string) error {
fmt.Println()
fmt.Printf(" %s⚠ DESTRUCTIVE OPERATION%s\n", r, rst)
fmt.Println()
fmt.Printf(" This will permanently remove all %s%d mob(s)%s and their worktrees.\n", r, len(cfg.Mobs), rst)
fmt.Println(" The following mobs will be permanently removed:")
fmt.Println()
var buf bytes.Buffer
w := tabwriter.NewWriter(&buf, 0, 0, 2, ' ', 0)
fmt.Fprintln(w, "NAME\tBRANCH")
for _, m := range cfg.Mobs {
branch := mob.ActualBranch(root, cfg, &m)
fmt.Fprintf(w, "%s\t%s\n", m.Name, branch)
}
w.Flush()
for _, line := range strings.Split(strings.TrimRight(buf.String(), "\n"), "\n") {
fmt.Printf(" %s\n", line)
}
fmt.Println()
fmt.Printf(" Any %suncommitted or unpushed changes%s in those worktrees will be %spermanently lost%s.\n", r, rst, r, rst)
fmt.Println()
fmt.Printf(" %sThis cannot be undone.%s\n", r, rst)
Expand Down
9 changes: 9 additions & 0 deletions internal/mob/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,15 @@ func TestPurge(t *testing.T) {
t.Fatalf("clear failed: %s\n%s", err, out)
}

// then -> output lists mob names and branches before confirmation
outStr := string(out)
if !strings.Contains(outStr, "one") || !strings.Contains(outStr, "mob/one") {
t.Errorf("purge output should list mob 'one' with branch, got: %s", outStr)
}
if !strings.Contains(outStr, "two") || !strings.Contains(outStr, "mob/two") {
t.Errorf("purge output should list mob 'two' with branch, got: %s", outStr)
}

// then -> no mobs
cfg := readConfig(t, repoPath)
mobs, _ := cfg["mobs"].([]interface{})
Expand Down
Loading