Skip to content

Commit 938c7e3

Browse files
author
Ben Chatelain
committed
Remove assumption that local and remote branches have same shortName
1 parent 7c9e2ee commit 938c7e3

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

ObjectiveGit/GTRepository+RemoteOperations.m

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,19 @@ - (BOOL)pushBranches:(NSArray *)branches toRemote:(GTRemote *)remote withOptions
185185
// Build refspecs for the passed in branches
186186
refspecs = [NSMutableArray arrayWithCapacity:branches.count];
187187
for (GTBranch *branch in branches) {
188-
// Assumes upstream branch reference has same name as local tracking branch
189-
[refspecs addObject:[NSString stringWithFormat:@"%@:%@", branch.reference.name, branch.reference.name]];
188+
// Default remote reference for when branch doesn't exist on remote - create with same short name
189+
NSString *remoteBranchReference = [NSString stringWithFormat:@"refs/heads/%@", branch.shortName];
190+
191+
BOOL success = NO;
192+
GTBranch *trackingBranch = [branch trackingBranchWithError:error success:&success];
193+
194+
if (success && trackingBranch) {
195+
// Use remote branch short name from trackingBranch, which could be different
196+
// (e.g. refs/heads/master:refs/heads/my_master)
197+
remoteBranchReference = [NSString stringWithFormat:@"refs/heads/%@", trackingBranch.shortName];
198+
}
199+
200+
[refspecs addObject:[NSString stringWithFormat:@"refs/heads/%@:%@", branch.shortName, remoteBranchReference]];
190201
}
191202

192203
return [self pushRefspecs:refspecs toRemote:remote withOptions:options error:error progress:progressBlock];

ObjectiveGitTests/GTRemotePushSpec.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,12 @@
184184
localTrackingBranch = [masterBranch trackingBranchWithError:&error success:&success];
185185
expect(error).to(beNil());
186186
expect(@(success)).to(beTrue());
187-
// expect(@([localTrackingBranch numberOfCommitsWithError:NULL])).to(equal(@3));
187+
expect(@([localTrackingBranch numberOfCommitsWithError:NULL])).to(equal(@4));
188188

189-
// Refetch master branch to ensure the commit count is accurate
189+
// Refresh remote master branch to ensure the commit count is accurate
190190
remoteMasterBranch = localBranchWithName(@"master", remoteRepo);
191191

192-
// Number of commits on remote after push
192+
// Number of commits in remote repo after push
193193
expect(@([remoteMasterBranch numberOfCommitsWithError:NULL])).to(equal(@4));
194194

195195
// Verify commit is in remote

0 commit comments

Comments
 (0)