Skip to content

Commit ad13540

Browse files
author
Robert Kyriakis
committed
Ask before deleting a remote branch also on the remote
1 parent 698426a commit ad13540

File tree

3 files changed

+70
-9
lines changed

3 files changed

+70
-9
lines changed

PBGitRepository.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ dispatch_queue_t PBGetWorkQueue();
6262
BOOL didCheckBareRepository;
6363
BOOL bareRepository;
6464
NSString* workingDirectory;
65+
66+
PBGitRef *actRef;
6567
}
6668
@property (nonatomic, strong, readonly) PBStashController *stashController;
6769
@property (nonatomic, strong, readonly) PBSubmoduleController *submoduleController;

PBGitRepository.m

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,14 @@
2727
#import "PBGitStash.h"
2828
#import "PBGitSubmodule.h"
2929

30+
#define kDialogDeleteRemoteBranch @"Delete Remote Branch"
31+
#define kDialogDeleteRemoteTag @"Delete Remote Tag"
32+
33+
3034
NSString* PBGitRepositoryErrorDomain = @"GitXErrorDomain";
3135

3236
@interface PBGitRepository()
37+
- (void)checkDeleteRemoteBranch:(PBGitRef *)ref;
3338
@end
3439

3540
dispatch_queue_t PBGetWorkQueue() {
@@ -1277,6 +1282,56 @@ - (BOOL) deleteRemote:(PBGitRef *)ref
12771282
}
12781283

12791284

1285+
- (void)checkDeleteRemoteBranch:(PBGitRef *)ref
1286+
{
1287+
if (!ref || ([ref refishType] != kGitXRemoteBranchType) )
1288+
{
1289+
return;
1290+
}
1291+
1292+
if (![self isRemoteConnected:ref])
1293+
{
1294+
[[NSAlert alertWithMessageText:[NSString stringWithFormat:@"Remote %@ is not conneted!",[ref remoteName]]
1295+
defaultButton:@"OK"
1296+
alternateButton:nil
1297+
otherButton:nil
1298+
informativeTextWithFormat:[NSString stringWithFormat:@"Can't remove the branch %@ from the remote %@",[ref remoteBranchName],[ref remoteName]]]
1299+
runModal];
1300+
return;
1301+
}
1302+
1303+
if ([PBGitDefaults isDialogWarningSuppressedForDialog:kDialogDeleteRemoteBranch]) {
1304+
[self deleteRemoteBranch:ref];
1305+
}
1306+
1307+
NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:@"Delete remotebranch %@ also on remote %@?",[ref remoteBranchName],[ref remoteName] ]
1308+
defaultButton:@"Delete"
1309+
alternateButton:@"Cancel"
1310+
otherButton:nil
1311+
informativeTextWithFormat:@"Are you sure you want to remove the remotebranch %@ also on remote %@?",[ref remoteBranchName],[ref remoteName]];
1312+
[alert setShowsSuppressionButton:YES];
1313+
1314+
[alert beginSheetModalForWindow:[[self windowController] window]
1315+
modalDelegate:self
1316+
didEndSelector:@selector(checkDeleteRemoteBranchSheetDidEnd:returnCode:contextInfo:)
1317+
contextInfo:Nil];
1318+
actRef = ref;
1319+
}
1320+
1321+
1322+
- (void)checkDeleteRemoteBranchSheetDidEnd:(NSAlert *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
1323+
{
1324+
[[sheet window] orderOut:nil];
1325+
1326+
if ([[sheet suppressionButton] state] == NSOnState)
1327+
[PBGitDefaults suppressDialogWarningForDialog:kDialogDeleteRemoteBranch];
1328+
1329+
if (returnCode == NSAlertDefaultReturn) {
1330+
[self deleteRemoteBranch:actRef];
1331+
}
1332+
}
1333+
1334+
12801335
- (BOOL) deleteRemoteBranch:(PBGitRef *)ref
12811336
{
12821337
if (!ref || ([ref refishType] != kGitXRemoteBranchType) )
@@ -1293,6 +1348,8 @@ - (BOOL) deleteRemoteBranch:(PBGitRef *)ref
12931348
return YES;
12941349
}
12951350

1351+
1352+
12961353
- (BOOL) deleteRemoteTag:(PBGitRef *)ref
12971354
{
12981355
if (!ref || ([ref refishType] != kGitXTagType) || ![self hasRemotes])
@@ -1340,14 +1397,6 @@ - (BOOL) deleteRef:(PBGitRef *)ref
13401397
{
13411398
return [self deleteRemote:ref];
13421399
}
1343-
else if ([ref refishType] == kGitXRemoteBranchType)
1344-
{
1345-
[self deleteRemoteBranch:ref];
1346-
}
1347-
else if ([ref refishType] == kGitXTagType)
1348-
{
1349-
[self deleteRemoteTag:ref];
1350-
}
13511400

13521401
int retValue = 1;
13531402
NSArray *arguments = [NSArray arrayWithObjects:@"update-ref", @"-d", [ref ref], nil];
@@ -1362,6 +1411,15 @@ - (BOOL) deleteRef:(PBGitRef *)ref
13621411
PBGitCommit *commit = [self commitForRef:ref];
13631412
[commit removeRef:ref];
13641413

1414+
if ([ref refishType] == kGitXRemoteBranchType)
1415+
{
1416+
[self checkDeleteRemoteBranch:ref];
1417+
}
1418+
else if ([ref refishType] == kGitXTagType)
1419+
{
1420+
[self deleteRemoteTag:ref];
1421+
}
1422+
13651423
[self reloadRefs];
13661424
return YES;
13671425
}

PBRefController.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
#define kDialogConfirmPush @"Confirm Push"
2323
#define kDialogDeleteRef @"Delete Ref"
2424
#define kDialogRenameRef @"Rename Ref"
25-
25+
#define kDialogDeleteRemoteBranch @"Delete Remote Branch"
26+
#define kDialogDeleteRemoteTag @"Delete Remote Tag"
2627

2728
@implementation PBRefController
2829

0 commit comments

Comments
 (0)