diff options
Diffstat (limited to 'refstore/shorten_test.go')
| -rw-r--r-- | refstore/shorten_test.go | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/refstore/shorten_test.go b/refstore/shorten_test.go new file mode 100644 index 00000000..1975ab3f --- /dev/null +++ b/refstore/shorten_test.go @@ -0,0 +1,68 @@ +package refstore_test + +import ( + "testing" + + "codeberg.org/lindenii/furgit/refstore" +) + +func TestShortenName(t *testing.T) { + t.Parallel() + + t.Run("simple", func(t *testing.T) { + got := refstore.ShortenName("refs/heads/main", []string{"refs/heads/main"}) + if got != "main" { + t.Fatalf("ShortenName simple = %q, want %q", got, "main") + } + }) + + t.Run("ambiguous with tags", func(t *testing.T) { + got := refstore.ShortenName( + "refs/heads/main", + []string{ + "refs/heads/main", + "refs/tags/main", + }, + ) + if got != "heads/main" { + t.Fatalf("ShortenName tags ambiguity = %q, want %q", got, "heads/main") + } + }) + + t.Run("strict remote head ambiguity", func(t *testing.T) { + // In strict mode, refs/remotes/%s/HEAD blocks shortening to "%s". + got := refstore.ShortenName( + "refs/heads/main", + []string{ + "refs/heads/main", + "refs/remotes/main/HEAD", + }, + ) + if got != "heads/main" { + t.Fatalf("ShortenName strict ambiguity = %q, want %q", got, "heads/main") + } + }) + + t.Run("deep fallback still shortens", func(t *testing.T) { + // refs/remotes/origin/main conflicts with refs/heads/origin/main for + // "origin/main", so it should fall back to "remotes/origin/main". + got := refstore.ShortenName( + "refs/remotes/origin/main", + []string{ + "refs/remotes/origin/main", + "refs/heads/origin/main", + }, + ) + if got != "remotes/origin/main" { + t.Fatalf("ShortenName deep fallback = %q, want %q", got, "remotes/origin/main") + } + }) + + t.Run("refs-prefix fallback", func(t *testing.T) { + name := "refs/notes/review/topic" + got := refstore.ShortenName(name, []string{name}) + if got != "notes/review/topic" { + t.Fatalf("ShortenName refs-prefix fallback = %q, want %q", got, "notes/review/topic") + } + }) +} |
