diff options
| author | William Bain <[email protected]> | 2022-02-24 22:21:35 -0500 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-02-24 19:21:35 -0800 |
| commit | eae00773cce87d5282a8ac7c10b5c1961ee6f9cb (patch) | |
| tree | f79c23762f5706972e45e2dfe26ac40b46862972 /refspec_test.go | |
| parent | e7d1b2b69fbe476c75a00cf8dcda284337facb50 (diff) | |
Add refspec bindings (#898)
This add support for the parse, access, and transform functions for
refspec objects.
Diffstat (limited to 'refspec_test.go')
| -rw-r--r-- | refspec_test.go | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/refspec_test.go b/refspec_test.go new file mode 100644 index 0000000..7064198 --- /dev/null +++ b/refspec_test.go @@ -0,0 +1,75 @@ +package git + +import ( + "testing" +) + +func TestRefspec(t *testing.T) { + t.Parallel() + + const ( + input = "+refs/heads/*:refs/remotes/origin/*" + mainLocal = "refs/heads/main" + mainRemote = "refs/remotes/origin/main" + ) + + refspec, err := ParseRefspec(input, true) + checkFatal(t, err) + + // Accessors + + s := refspec.String() + if s != input { + t.Errorf("expected string %q, got %q", input, s) + } + + if d := refspec.Direction(); d != ConnectDirectionFetch { + t.Errorf("expected fetch refspec, got direction %v", d) + } + + if pat, expected := refspec.Src(), "refs/heads/*"; pat != expected { + t.Errorf("expected refspec src %q, got %q", expected, pat) + } + + if pat, expected := refspec.Dst(), "refs/remotes/origin/*"; pat != expected { + t.Errorf("expected refspec dst %q, got %q", expected, pat) + } + + if !refspec.Force() { + t.Error("expected refspec force flag") + } + + // SrcMatches + + if !refspec.SrcMatches(mainLocal) { + t.Errorf("refspec source did not match %q", mainLocal) + } + + if refspec.SrcMatches("refs/tags/v1.0") { + t.Error("refspec source matched under refs/tags") + } + + // DstMatches + + if !refspec.DstMatches(mainRemote) { + t.Errorf("refspec destination did not match %q", mainRemote) + } + + if refspec.DstMatches("refs/tags/v1.0") { + t.Error("refspec destination matched under refs/tags") + } + + // Transforms + + fromLocal, err := refspec.Transform(mainLocal) + checkFatal(t, err) + if fromLocal != mainRemote { + t.Errorf("transform by refspec returned %s; expected %s", fromLocal, mainRemote) + } + + fromRemote, err := refspec.Rtransform(mainRemote) + checkFatal(t, err) + if fromRemote != mainLocal { + t.Errorf("rtransform by refspec returned %s; expected %s", fromRemote, mainLocal) + } +} |
