diff --git a/linux/cli.go b/linux/cli.go index 8b0da31..32e3791 100644 --- a/linux/cli.go +++ b/linux/cli.go @@ -646,7 +646,7 @@ func configAppend(line string) { } func configMatches(spec *RepoSpec, nameOrPath string) bool { - return spec.Path == expandTilde(nameOrPath) || spec.Name() == nameOrPath || spec.Path == nameOrPath + return spec.Name() == nameOrPath || spec.Path == nameOrPath || spec.Path == normalizePath(nameOrPath) } func configRemove(nameOrPath string) int { @@ -673,10 +673,9 @@ func configRemove(nameOrPath string) int { return removed } -// Flip the --paused token on config lines matching `nameOrPath` (by full -// path or repo name, like remove). Pause lives in the config, not daemon -// state, so it survives daemon and machine restarts. Returns the number -// of lines changed. +// Flip the --paused token on config lines matching `nameOrPath` (as remove +// matches). Pause lives in the config, not daemon state, so it survives +// daemon and machine restarts. Returns the number of lines changed. func configSetPaused(nameOrPath string, paused bool) int { raw, err := os.ReadFile(configPath()) if err != nil { diff --git a/linux/cli_test.go b/linux/cli_test.go index 898ee96..a18c054 100644 --- a/linux/cli_test.go +++ b/linux/cli_test.go @@ -123,6 +123,45 @@ func TestRmMatchesByFullPath(t *testing.T) { } } +func TestRmMatchesTheRepoItRunsIn(t *testing.T) { + withTemporaryConfig(t) + repo := newTestRepo(t) + cliRun([]string{repo.path}) + t.Chdir(repo.path) + if cliRun([]string{"rm", "."}) != 0 { + t.Error("rm . failed") + } + if len(configSpecs()) != 0 { + t.Error("the entry should be gone") + } +} + +func TestRmMatchesARelativePath(t *testing.T) { + withTemporaryConfig(t) + repo := newTestRepo(t) + cliRun([]string{repo.path}) + t.Chdir(filepath.Dir(repo.path)) + if cliRun([]string{"rm", "./" + repo.spec().Name()}) != 0 { + t.Error("rm by relative path failed") + } + if len(configSpecs()) != 0 { + t.Error("the entry should be gone") + } +} + +func TestRmMatchesByNameFromAnUnrelatedDirectory(t *testing.T) { + withTemporaryConfig(t) + repo := newTestRepo(t) + cliRun([]string{repo.path}) + t.Chdir(t.TempDir()) + if cliRun([]string{"rm", repo.spec().Name()}) != 0 { + t.Error("rm by name failed") + } + if len(configSpecs()) != 0 { + t.Error("the entry should be gone") + } +} + func TestRmUnknownFailsAndLeavesConfigAlone(t *testing.T) { withTemporaryConfig(t) repo := newTestRepo(t) @@ -171,6 +210,25 @@ func TestPauseByFullPath(t *testing.T) { } } +func TestPauseAndResumeTakeARelativeTarget(t *testing.T) { + withTemporaryConfig(t) + repo := newTestRepo(t) + cliRun([]string{repo.path}) + t.Chdir(repo.path) + if cliRun([]string{"pause", "."}) != 0 { + t.Fatal("pause . failed") + } + if !configSpecs()[0].Paused { + t.Error("spec should be paused") + } + if cliRun([]string{"resume", "."}) != 0 { + t.Fatal("resume . failed") + } + if configSpecs()[0].Paused { + t.Error("spec should be resumed") + } +} + func TestPausingTwiceFailsPolitely(t *testing.T) { withTemporaryConfig(t) repo := newTestRepo(t)