GitRepo.setHead

Make the repository HEAD point to the specified reference.

If the provided reference points to a Tree or a Blob, the HEAD is unaltered and -1 is returned.

If the provided reference points to a branch, the HEAD will point to that branch, staying attached, or become attached if it isn't yet. If the branch doesn't exist yet, no error will be return. The HEAD will then be attached to an unborn branch.

Otherwise, the HEAD will be detached and will directly point to the Commit.

@param repo Repository pointer @param refname Canonical name of the reference the HEAD should point at @return 0 on success, or an error code

struct GitRepo
version(none)
void
setHead
(
in char[] refName
)

Examples

1 auto repo = initRepo(_userRepo, OpenBare.no);
2 
3 scope(exit)
4 {
5     // workaround for Issue 10529:
6     // http://d.puremagic.com/issues/show_bug.cgi?id=10529
7     version(Windows)
8         executeShell(format("rmdir /q /s %s", _userRepo.absolutePath.buildNormalizedPath));
9     else
10         rmdirRecurse(_userRepo);
11 }
12 
13 // create a blob file in the work path
14 string blobPath = buildPath(repo.workPath, "foo.text");
15 std.file.write(blobPath, "blob");
16 
17 import deimos.git2.blob;
18 git_oid _oid;
19 require(0 == git_blob_create_fromworkdir(&_oid, repo._data._payload, "/foo.text"));
20 
21 import deimos.git2.refs;
22 git_reference* ptr;
23 require(0 == git_reference_create(&ptr, repo._data._payload, "MY_REF", &_oid, false));
24 
25 repo.setHead("MY_REF");

Meta