|
120 | 120 | expect(@(lastIndex)).to(equal(@2));
|
121 | 121 | });
|
122 | 122 |
|
| 123 | +it(@"should apply stashes", ^{ |
| 124 | + expect(@([@"foobar" writeToURL:[repository.fileURL URLByAppendingPathComponent:@"new-test-file"] atomically:YES encoding:NSUTF8StringEncoding error:NULL])).to(beTruthy()); |
| 125 | + |
| 126 | + NSError *error = nil; |
| 127 | + GTCommit *stash = [repository stashChangesWithMessage:nil flags:GTRepositoryStashFlagIncludeUntracked error:&error]; |
| 128 | + expect(stash).notTo(beNil()); |
| 129 | + expect(error).to(beNil()); |
| 130 | + |
| 131 | + __block BOOL progressCalled = NO; |
| 132 | + BOOL success = [repository applyStashAtIndex:0 flags:GTRepositoryStashApplyFlagDefault error:&error progressBlock:^void(GTRepositoryStashApplyProgress step, BOOL *stop) { |
| 133 | + progressCalled = YES; |
| 134 | + }]; |
| 135 | + expect(@(success)).to(beTruthy()); |
| 136 | + expect(@(progressCalled)).to(beTruthy()); |
| 137 | + expect(error).to(beNil()); |
| 138 | + |
| 139 | + expect([NSString stringWithContentsOfURL:[repository.fileURL URLByAppendingPathComponent:@"new-test-file"] encoding:NSUTF8StringEncoding error:NULL]).to(equal(@"foobar")); |
| 140 | +}); |
| 141 | + |
| 142 | + |
| 143 | +it(@"should drop stashes", ^{ |
| 144 | + expect(@([@"foobar" writeToURL:[repository.fileURL URLByAppendingPathComponent:@"new-test-file"] atomically:YES encoding:NSUTF8StringEncoding error:NULL])).to(beTruthy()); |
| 145 | + |
| 146 | + NSError *error = nil; |
| 147 | + GTCommit *stash = [repository stashChangesWithMessage:nil flags:GTRepositoryStashFlagIncludeUntracked error:&error]; |
| 148 | + expect(stash).notTo(beNil()); |
| 149 | + expect(error).to(beNil()); |
| 150 | + |
| 151 | + BOOL success = [repository dropStashAtIndex:0 error:&error]; |
| 152 | + expect(@(success)).to(beTruthy()); |
| 153 | + expect(error).to(beNil()); |
| 154 | +}); |
| 155 | + |
| 156 | +it(@"should fail to apply/drop unknown stashes", ^{ |
| 157 | + NSError *error = nil; |
| 158 | + BOOL success = NO; |
| 159 | + |
| 160 | + __block NSUInteger lastStashIndex = 0; |
| 161 | + [repository enumerateStashesUsingBlock:^(NSUInteger index, NSString * __nullable message, GTOID * __nullable oid, BOOL * __nonnull stop) { |
| 162 | + lastStashIndex = index; |
| 163 | + }]; |
| 164 | + |
| 165 | + success = [repository applyStashAtIndex:(lastStashIndex + 1) flags:GTRepositoryStashApplyFlagDefault error:&error progressBlock:nil]; |
| 166 | + expect(@(success)).to(beFalsy()); |
| 167 | + expect(error).notTo(beNil()); |
| 168 | + expect(error.domain).to(equal(GTGitErrorDomain)); |
| 169 | + expect(@(error.code)).to(equal(@(GIT_ENOTFOUND))); |
| 170 | + |
| 171 | + success = [repository dropStashAtIndex:(lastStashIndex + 1) error:&error]; |
| 172 | + expect(@(success)).to(beFalsy()); |
| 173 | + expect(error).notTo(beNil()); |
| 174 | + expect(error.domain).to(equal(GTGitErrorDomain)); |
| 175 | + expect(@(error.code)).to(equal(@(GIT_ENOTFOUND))); |
| 176 | +}); |
| 177 | + |
| 178 | +it(@"should fail to apply conflicting stashes", ^{ |
| 179 | + expect(@([@"foobar" writeToURL:[repository.fileURL URLByAppendingPathComponent:@"new-test-file"] atomically:YES encoding:NSUTF8StringEncoding error:NULL])).to(beTruthy()); |
| 180 | + |
| 181 | + NSError *error = nil; |
| 182 | + GTCommit *stash = [repository stashChangesWithMessage:nil flags:GTRepositoryStashFlagIncludeUntracked error:&error]; |
| 183 | + expect(stash).notTo(beNil()); |
| 184 | + expect(error).to(beNil()); |
| 185 | + |
| 186 | + |
| 187 | + expect(@([@"barfoo" writeToURL:[repository.fileURL URLByAppendingPathComponent:@"new-test-file"] atomically:YES encoding:NSUTF8StringEncoding error:NULL])).to(beTruthy()); |
| 188 | + |
| 189 | + BOOL success = [repository applyStashAtIndex:0 flags:GTRepositoryStashApplyFlagDefault error:&error progressBlock:nil]; |
| 190 | + expect(@(success)).to(beFalsy()); |
| 191 | + expect(error).notTo(beNil()); |
| 192 | + |
| 193 | + expect(error.domain).to(equal(GTGitErrorDomain)); |
| 194 | + expect(@(error.code)).to(equal(@(GIT_ECONFLICT))); |
| 195 | +}); |
| 196 | + |
123 | 197 | afterEach(^{
|
124 | 198 | [self tearDown];
|
125 | 199 | });
|
|
0 commit comments