Walk the FETCH_HEAD file with a function.
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()); static ContinueWalk walkFunc(in char[] refName, in char[] remoteURL, GitOid oid, bool isMerge) { static int count; count++; assert(count != 2); // we're stopping after the first iteration assert(refName == "refs/heads/master"); assert(remoteURL == "git://github.com/D-Programming-Language/dmd"); assert(oid == GitOid("23C3C6ADD8162693F85B3B41C9BF6550A71A57D3")); return ContinueWalk.no; } repo.walkFetchHead(&walkFunc);
Walk the FETCH_HEAD file with a delegate.
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()); struct S { size_t count; // delegate walker ContinueWalk walker(in char[] refName, in char[] remoteURL, GitOid oid, bool isMerge) { 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)); return ContinueWalk.yes; } ~this() { assert(count == 2); // verify we've walked through all the items } } S s; repo.walkFetchHead(&s.walker);
Call the callback function for each entry in the FETCH_HEAD file in this repository.
The callback type must be either FetchHeadFunction or FetchHeadDelegate.
This function will return when either all entries are exhausted or when the callback returns ContinueWalk.no.