File tree Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -119,6 +119,16 @@ typedef enum {
119
119
// / if updating or saving the remote failed.
120
120
- (BOOL )updateURLString : (NSString *)URLString error : (NSError **)error ;
121
121
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
+
122
132
// / Adds a fetch refspec to this remote.
123
133
// /
124
134
// / fetchRefspec - The fetch refspec string to add. May not be nil.
Original file line number Diff line number Diff line change @@ -204,6 +204,21 @@ - (BOOL)updateURLString:(NSString *)URLString error:(NSError **)error {
204
204
return YES ;
205
205
}
206
206
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
+
207
222
- (BOOL )addFetchRefspec : (NSString *)fetchRefspec error : (NSError **)error {
208
223
NSParameterAssert (fetchRefspec != nil );
209
224
Original file line number Diff line number Diff line change 61
61
expect (remote.URLString ).to (equal (newURLString));
62
62
});
63
63
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
+
64
79
it (@" fetch refspecs" , ^{
65
80
expect (remote.fetchRefspecs ).to (equal (@[ fetchRefspec ]));
66
81
You can’t perform that action at this time.
0 commit comments