How to set up an initial repository with some branches to operate on?

35 views Asked by At

I've been chipping away at trying to better understand how to set up the initial state of a test within my application. The initial setup that I need is fairly minimal:

  1. Set up a git repository for my tests to run on.
  2. Create a few branches.
  3. Create a file on one of the branches.

I think that from this setup I can get further on my own. I've looked at the common_test.go package and there seems to be some helpful structs and functions here, but they depend on fixtures from go-get/fixtures, which seem to only pull remote repositories.

Pulling something remote is not necessarily what I need to do, so that seems to be out-of-scope.

I suspect I need to do something with the billy filesystem interface, but I haven't quite figured out how to leverage this to do what I need yet.

So far I have something, but it doesn't work as expected. For example, when I create all of the branches on the repo, I am unable to iterate over them with ForEach(), at all. In fact, I don't even think the function passed to ForEach() gets called. What I find strange, though, is if I do something like b, err := repo.Branch("refs/heads/JOB-62131/JOB-76475/add-location-timers-to-fms") then I can get that branch back without error.

func TestCommonSuiteExample(t *testing.T) {
    repo, _ := git.Init(memory.NewStorage(), memfs.New())
    branchNames := []string{
        "refs/heads/JOB-62131/JOB-76475/add-location-timers-to-fms",
        "refs/heads/JOB-62131/JOB-76477/store-feature-enablement",
        "refs/heads/JOB-62131/JOB-77400/show-modal-dialogue-on-disablement",
    }

    for _, b := range branchNames {
        opts := &config.Branch{Name: b}
        err := repo.CreateBranch(opts)
        if err != nil {
            log.Fatal(err)
        }
    }
    branches, _ := repo.Branches()

        // Branches don't seem to get iterated over here, not sure why.
    branches.ForEach(func(ref *plumbing.Reference) error {
        fmt.Print(ref.Name().IsBranch()) 
        return nil
    })
}

0

There are 0 answers