GitRepo.walkFetchHead

Walk the FETCH_HEAD file in a foreach loop.

Examples

Walk the FETCH_HEAD using a foreach loop.

auto repo = initRepo(_userRepo, OpenBare.yes);
scope(exit) rmdirRecurse(_userRepo);

string[] fetchHeadItems = [
    "23c3c6add8162693f85b3b41c9bf6550a71a57d3		branch 'master' of git://github.com/D-Programming-Language/dmd\n",
    "aaf64112624abab1f6cc8f610223f6e12b525e09		branch 'master' of git://github.com/D-Programming-Language/dmd\n"
];

std.file.write(buildPath(repo.path, "FETCH_HEAD"), fetchHeadItems.join());

size_t count;
foreach (refName, remoteURL, oid, isMerge; repo.walkFetchHead)
{
    string line = fetchHeadItems[count++];
    string commitHex = line.split[0];

    assert(refName == "refs/heads/master");
    assert(remoteURL == "git://github.com/D-Programming-Language/dmd");
    assert(oid == GitOid(commitHex));
}

// ensure we've iterated all itmes
assert(count == 2);

count = 0;
foreach (refName, remoteURL, oid, isMerge; repo.walkFetchHead)
{
    string line = fetchHeadItems[count++];
    string commitHex = line.split[0];

    assert(refName == "refs/heads/master");
    assert(remoteURL == "git://github.com/D-Programming-Language/dmd");
    assert(oid == GitOid(commitHex));
    break;
}

// ensure 'break' works
assert(count == 1);

Meta