Skip to content

Commit aa56ea4

Browse files
authored
MapView: Choosing not head local branch to delete. (#579)
* kit: map view choosing not head local branch to delete has been added. * pull request: necessary changes have been added.
1 parent b5fe2bf commit aa56ea4

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

GitUpKit/Views/GIMapViewController.m

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -940,9 +940,24 @@ - (IBAction)revertSelectedCommit:(id)sender {
940940
[self revertCommit:commit againstLocalBranch:self.repository.history.HEADBranch];
941941
}
942942

943+
- (GCHistoryLocalBranch *)branchToDeleteForSelectedCommit:(GCHistoryCommit *)commit {
944+
NSArray <GCHistoryLocalBranch *>* localBranches = commit.localBranches;
945+
NSString *headBranchName = self.repository.history.HEADBranch.name;
946+
947+
NSInteger index = [localBranches indexOfObjectPassingTest:^BOOL(GCHistoryLocalBranch * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
948+
return ![headBranchName isEqualToString:obj.name];
949+
}];
950+
951+
if (index == NSNotFound) {
952+
return localBranches.firstObject;
953+
}
954+
955+
return localBranches[index];
956+
}
957+
943958
- (IBAction)deleteSelectedCommit:(id)sender {
944959
GCHistoryCommit* commit = _graphView.selectedCommit;
945-
GCHistoryLocalBranch* localBranch = commit.localBranches.firstObject;
960+
GCHistoryLocalBranch* localBranch = [self branchToDeleteForSelectedCommit:commit];
946961
if (localBranch) {
947962
NSAlert* alert = [[NSAlert alloc] init];
948963
alert.messageText = NSLocalizedString(@"Do you want to delete the commit or the local branch?", nil);

0 commit comments

Comments
 (0)