Skip to content

Commit b64f024

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 0871b0e + 7febb4f commit b64f024

File tree

7 files changed

+62
-2
lines changed

7 files changed

+62
-2
lines changed

ObjectiveGit/GTCredential.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ NS_ASSUME_NONNULL_BEGIN
3232
///
3333
/// credentialBlock - a block that will be called when credentials are requested.
3434
/// Must not be nil.
35-
+ (instancetype)providerWithBlock:(GTCredential *(^)(GTCredentialType type, NSString *URL, NSString *userName))credentialBlock;
35+
+ (instancetype)providerWithBlock:(GTCredential * _Nullable(^)(GTCredentialType type, NSString *URL, NSString *userName))credentialBlock;
3636

3737
/// Default credential provider method.
3838
///
@@ -46,7 +46,7 @@ NS_ASSUME_NONNULL_BEGIN
4646
/// type - the credential types allowed by the operation.
4747
/// URL - the URL the operation is authenticating against.
4848
/// userName - the user name provided by the operation. Can be nil, and might be ignored.
49-
- (GTCredential *)credentialForType:(GTCredentialType)type URL:(NSString *)URL userName:(nullable NSString *)userName;
49+
- (GTCredential * _Nullable)credentialForType:(GTCredentialType)type URL:(NSString *)URL userName:(nullable NSString *)userName;
5050
@end
5151

5252
/// The GTCredential class is used to provide authentication data.

ObjectiveGit/GTDiffHunk.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ NS_ASSUME_NONNULL_BEGIN
2222
/// The number of lines represented in the hunk.
2323
@property (nonatomic, readonly) NSUInteger lineCount;
2424

25+
/// The starting line number in the old file
26+
@property (nonatomic, readonly) NSUInteger oldStart;
27+
28+
/// The number of lines in the old file
29+
@property (nonatomic, readonly) NSUInteger oldLines;
30+
31+
/// The starting line number in the new file
32+
@property (nonatomic, readonly) NSUInteger newStart;
33+
34+
/// The number of lines in the new file
35+
@property (nonatomic, readonly) NSUInteger newLines;
36+
2537
- (instancetype)init NS_UNAVAILABLE;
2638

2739
/// Designated initialiser.

ObjectiveGit/GTDiffHunk.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ - (instancetype)initWithPatch:(GTDiffPatch *)patch hunkIndex:(NSUInteger)hunkInd
4040
int result = git_patch_get_hunk(&_git_hunk, &gitLineCount, patch.git_patch, hunkIndex);
4141
if (result != GIT_OK) return nil;
4242
_lineCount = gitLineCount;
43+
_oldStart = self.git_hunk->old_start;
44+
_oldLines = self.git_hunk->old_lines;
45+
_newStart = self.git_hunk->new_start;
46+
_newLines = self.git_hunk->new_lines;
4347

4448
_patch = patch;
4549
_hunkIndex = hunkIndex;

ObjectiveGit/GTRemote.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,16 @@ typedef enum {
119119
/// if updating or saving the remote failed.
120120
- (BOOL)updateURLString:(NSString *)URLString error:(NSError **)error;
121121

122+
/// Updates the push URL string for this remote.
123+
///
124+
/// URLString - The URLString to update to. May not be nil.
125+
/// error - If not NULL, this will be set to any error that occurs when
126+
/// updating the URLString or saving the remote.
127+
///
128+
/// Returns YES if the push URLString was successfully updated, NO and an error
129+
/// if updating or saving the remote failed.
130+
- (BOOL)updatePushURLString:(NSString *)URLString error:(NSError **)error;
131+
122132
/// Adds a fetch refspec to this remote.
123133
///
124134
/// fetchRefspec - The fetch refspec string to add. May not be nil.

ObjectiveGit/GTRemote.m

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,21 @@ - (BOOL)updateURLString:(NSString *)URLString error:(NSError **)error {
204204
return YES;
205205
}
206206

207+
- (BOOL)updatePushURLString:(NSString *)URLString error:(NSError **)error {
208+
NSParameterAssert(URLString != nil);
209+
210+
if ([self.pushURLString isEqualToString:URLString]) return YES;
211+
212+
int gitError = git_remote_set_pushurl(self.repository.git_repository, self.name.UTF8String, URLString.UTF8String);
213+
if (gitError != GIT_OK) {
214+
if (error != NULL) {
215+
*error = [NSError git_errorFor:gitError description:@"Failed to update remote push URL string."];
216+
}
217+
return NO;
218+
}
219+
return YES;
220+
}
221+
207222
- (BOOL)addFetchRefspec:(NSString *)fetchRefspec error:(NSError **)error {
208223
NSParameterAssert(fetchRefspec != nil);
209224

ObjectiveGitTests/GTDiffSpec.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@
112112
[patch enumerateHunksUsingBlock:^(GTDiffHunk *hunk, BOOL *stop) {
113113
expect(hunk.header).to(equal(@"@@ -4,7 +4,7 @@"));
114114
expect(@(hunk.lineCount)).to(equal(@8));
115+
expect(@(hunk.oldStart)).to(equal(@4));
116+
expect(@(hunk.oldLines)).to(equal(@7));
117+
expect(@(hunk.newStart)).to(equal(@4));
118+
expect(@(hunk.newLines)).to(equal(@7));
115119

116120
NSArray *expectedLines = @[ @"//",
117121
@"// Created by Joe Ricioppo on 9/29/10.",

ObjectiveGitTests/GTRemoteSpec.m

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,21 @@
6161
expect(remote.URLString).to(equal(newURLString));
6262
});
6363

64+
it(@"push URL string", ^{
65+
expect(remote.pushURLString).to(beNil());
66+
67+
NSString *newURLString = @"https://github.com/github/Test_App.git";
68+
69+
__block NSError *error = nil;
70+
expect(@([remote updatePushURLString:newURLString error:&error])).to(beTruthy());
71+
expect(error).to(beNil());
72+
73+
// Reload remote from disk to pick up the change
74+
remote = configuration.remotes[0];
75+
76+
expect(remote.pushURLString).to(equal(newURLString));
77+
});
78+
6479
it(@"fetch refspecs", ^{
6580
expect(remote.fetchRefspecs).to(equal(@[ fetchRefspec ]));
6681

0 commit comments

Comments
 (0)