| 618 | } |
| 619 | |
| 620 | func TestLocalRefs(t *testing.T) { |
| 621 | repo := test.NewRepo(t) |
| 622 | repo.Pushd() |
| 623 | defer func() { |
| 624 | repo.Popd() |
| 625 | repo.Cleanup() |
| 626 | }() |
| 627 | |
| 628 | repo.AddCommits([]*test.CommitInput{ |
| 629 | { |
| 630 | Files: []*test.FileInput{ |
| 631 | {Filename: "file1.txt", Size: 20}, |
| 632 | }, |
| 633 | }, |
| 634 | { |
| 635 | NewBranch: "branch", |
| 636 | ParentBranches: []string{"master"}, |
| 637 | Files: []*test.FileInput{ |
| 638 | {Filename: "file1.txt", Size: 20}, |
| 639 | }, |
| 640 | }, |
| 641 | }) |
| 642 | |
| 643 | test.RunGitCommand(t, true, "tag", "v1") |
| 644 | |
| 645 | refs, err := LocalRefs() |
| 646 | if err != nil { |
| 647 | t.Fatal(err) |
| 648 | } |
| 649 | |
| 650 | actual := make(map[string]bool) |
| 651 | for _, r := range refs { |
| 652 | t.Logf("REF: %s", r.Name) |
| 653 | switch r.Type { |
| 654 | case RefTypeHEAD: |
| 655 | t.Errorf("Local HEAD ref: %v", r) |
| 656 | case RefTypeOther: |
| 657 | t.Errorf("Stash or unknown ref: %v", r) |
| 658 | default: |
| 659 | actual[r.Name] = true |
| 660 | } |
| 661 | } |
| 662 | |
| 663 | expected := []string{"master", "branch", "v1"} |
| 664 | found := 0 |
| 665 | for _, refname := range expected { |
| 666 | if actual[refname] { |
| 667 | found += 1 |
| 668 | } else { |
| 669 | t.Errorf("could not find ref %q", refname) |
| 670 | } |
| 671 | } |
| 672 | |
| 673 | if found != len(expected) { |
| 674 | t.Errorf("Unexpected local refs: %v", actual) |
| 675 | } |
| 676 | } |
| 677 | |