Skip to content

Commit 8e6c27c

Browse files
committed
Rework checkout+notify tests to clarify expected behavior
1 parent c1e58a6 commit 8e6c27c

File tree

1 file changed

+20
-24
lines changed

1 file changed

+20
-24
lines changed

ObjectiveGitTests/GTRepositorySpec.m

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
QuickSpecBegin(GTRepositorySpec)
1616

17-
static NSString * const mainFile = @"main.m";
18-
static NSString * const readmeFile = @"README1.txt";
17+
static NSString * const readmeFile = @"README.md";
18+
static NSString * const readme1File = @"README1.txt";
1919

2020

2121
__block GTRepository *repository;
@@ -381,58 +381,54 @@
381381
});
382382

383383
describe(@"-checkout:strategy:notifyFlags:error:notifyBlock:progressBlock:", ^{
384-
it(@"should fail ref checkout with dirty file and notify", ^{
384+
it(@"should fail ref checkout with conflict and notify", ^{
385385
NSError *error = nil;
386386
GTReference *ref = [repository lookUpReferenceWithName:@"refs/heads/other-branch" error:&error];
387387
expect(ref).notTo(beNil());
388388
expect(error.localizedDescription).to(beNil());
389-
BOOL writeResult = [@"Replacement data in main.m\n" writeToURL:[repository.fileURL URLByAppendingPathComponent:mainFile] atomically:YES encoding:NSUTF8StringEncoding error:&error];
389+
BOOL writeResult = [@"Conflicting data in README.md\n" writeToURL:[repository.fileURL URLByAppendingPathComponent:readmeFile] atomically:YES encoding:NSUTF8StringEncoding error:&error];
390390
expect(@(writeResult)).to(beTruthy());
391391
__block NSUInteger notifyCount = 0;
392-
__block BOOL mainFileDirty = NO;
392+
__block BOOL readmeFileConflicted = NO;
393393
int (^notifyBlock)(GTCheckoutNotifyFlags, NSString *, GTDiffFile *, GTDiffFile *, GTDiffFile *);
394394
notifyBlock = ^(GTCheckoutNotifyFlags why, NSString *path, GTDiffFile *baseline, GTDiffFile *target, GTDiffFile *workdir) {
395395
notifyCount++;
396-
if([path isEqualToString:mainFile] && (why & GTCheckoutNotifyDirty)) {
397-
mainFileDirty = YES;
398-
return GIT_EUSER;
399-
} else {
400-
return 0;
396+
if([path isEqualToString:readmeFile] && (why & GTCheckoutNotifyConflict)) {
397+
readmeFileConflicted = YES;
401398
}
399+
return 0;
402400
};
403401

404-
BOOL result = [repository checkoutReference:ref strategy:GTCheckoutStrategySafe notifyFlags:GTCheckoutNotifyDirty error:&error progressBlock:nil notifyBlock:notifyBlock];
402+
BOOL result = [repository checkoutReference:ref strategy:GTCheckoutStrategySafe notifyFlags:GTCheckoutNotifyConflict error:&error progressBlock:nil notifyBlock:notifyBlock];
405403
expect(@(notifyCount)).to(equal(@(1)));
406-
expect(@(mainFileDirty)).to(beTruthy());
404+
expect(@(readmeFileConflicted)).to(beTruthy());
407405
expect(@(result)).to(beFalsy());
408-
expect(@(error.code)).to(equal(@(GIT_EUSER)));
406+
expect(@(error.code)).to(equal(@(GIT_ECONFLICT)));
409407
});
410408

411-
it(@"should fail commit checkout with dirty file and notify", ^{
409+
it(@"should fail commit checkout with conflict and notify", ^{
412410
NSError *error = nil;
413411
GTCommit *commit = [repository lookUpObjectBySHA:@"1d69f3c0aeaf0d62e25591987b93b8ffc53abd77" objectType:GTObjectTypeCommit error:&error];
414412
expect(commit).notTo(beNil());
415413
expect(error.localizedDescription).to(beNil());
416-
BOOL writeResult = [@"Replacement data in README\n" writeToURL:[repository.fileURL URLByAppendingPathComponent:readmeFile] atomically:YES encoding:NSUTF8StringEncoding error:&error];
414+
BOOL writeResult = [@"Conflicting data in README1.txt\n" writeToURL:[repository.fileURL URLByAppendingPathComponent:readme1File] atomically:YES encoding:NSUTF8StringEncoding error:&error];
417415
expect(@(writeResult)).to(beTruthy());
418416
__block NSUInteger notifyCount = 0;
419-
__block BOOL readmeFileDirty = NO;
417+
__block BOOL readme1FileConflicted = NO;
420418
int (^notifyBlock)(GTCheckoutNotifyFlags, NSString *, GTDiffFile *, GTDiffFile *, GTDiffFile *);
421419
notifyBlock = ^(GTCheckoutNotifyFlags why, NSString *path, GTDiffFile *baseline, GTDiffFile *target, GTDiffFile *workdir) {
422420
notifyCount++;
423-
if([path isEqualToString:readmeFile] && (why & GTCheckoutNotifyDirty)) {
424-
readmeFileDirty = YES;
425-
return GIT_EUSER;
426-
} else {
427-
return 0;
421+
if([path isEqualToString:readme1File] && (why & GTCheckoutNotifyConflict)) {
422+
readme1FileConflicted = YES;
428423
}
424+
return 0;
429425
};
430426

431-
BOOL result = [repository checkoutCommit:commit strategy:GTCheckoutStrategySafe notifyFlags:GTCheckoutNotifyDirty error:&error progressBlock:nil notifyBlock:notifyBlock];
427+
BOOL result = [repository checkoutCommit:commit strategy:GTCheckoutStrategySafe notifyFlags:GTCheckoutNotifyConflict error:&error progressBlock:nil notifyBlock:notifyBlock];
432428
expect(@(notifyCount)).to(equal(@(1)));
433-
expect(@(readmeFileDirty)).to(beTruthy());
429+
expect(@(readme1FileConflicted)).to(beTruthy());
434430
expect(@(result)).to(beFalsy());
435-
expect(@(error.code)).to(equal(@(GIT_EUSER)));
431+
expect(@(error.code)).to(equal(@(GIT_ECONFLICT)));
436432
});
437433
});
438434

0 commit comments

Comments
 (0)