Skip to content

Commit 9a65ad9

Browse files
committed
Add tests for moveHEAD
1 parent 141d957 commit 9a65ad9

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

ObjectiveGitTests/GTRepositorySpec.m

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,58 @@
358358
});
359359
});
360360

361+
describe(@"move head", ^{
362+
beforeEach(^{
363+
repository = self.testAppFixtureRepository;
364+
});
365+
366+
//- (BOOL)moveHEADToReference:(GTReference *)reference error:(NSError **)error;
367+
it(@"should move to reference", ^{
368+
NSError *error = nil;
369+
GTReference *originalHead = [repository headReferenceWithError:NULL];
370+
371+
GTReference *targetReference = [repository lookUpReferenceWithName:@"refs/heads/other-branch" error:NULL];
372+
expect(targetReference).notTo(beNil());
373+
374+
// -> Test the move
375+
BOOL success = [repository moveHEADToReference:targetReference error:&error];
376+
expect(@(success)).to(beTruthy());
377+
expect(error).to(beNil());
378+
379+
// Verify
380+
GTReference *head = [repository headReferenceWithError:&error];
381+
expect(head).notTo(beNil());
382+
expect(head).notTo(equal(originalHead));
383+
expect(head.targetOID.SHA).to(equal(targetReference.targetOID.SHA));
384+
});
385+
386+
//- (BOOL)moveHEADToCommit:(GTCommit *)commit error:(NSError **)error;
387+
it(@"should move to commit", ^{
388+
NSError *error = nil;
389+
GTReference *originalHead = [repository headReferenceWithError:NULL];
390+
NSString *targetCommitSHA = @"f7ecd8f4404d3a388efbff6711f1bdf28ffd16a0";
391+
392+
GTCommit *commit = [repository lookUpObjectBySHA:targetCommitSHA error:NULL];
393+
expect(commit).notTo(beNil());
394+
395+
GTCommit *originalHeadCommit = [repository lookUpObjectByOID:originalHead.targetOID error:NULL];
396+
expect(originalHeadCommit).notTo(beNil());
397+
398+
// -> Test the move
399+
BOOL success = [repository moveHEADToCommit:commit error:&error];
400+
expect(@(success)).to(beTruthy());
401+
expect(error).to(beNil());
402+
403+
// Test for detached?
404+
405+
// Verify
406+
GTReference *head = [repository headReferenceWithError:&error];
407+
expect(head).notTo(beNil());
408+
expect(head.targetOID.SHA).to(equal(targetCommitSHA));
409+
});
410+
});
411+
412+
361413
describe(@"-checkout:strategy:error:progressBlock:", ^{
362414
it(@"should allow references", ^{
363415
NSError *error = nil;

0 commit comments

Comments
 (0)