Skip to content

Commit 0c05990

Browse files
author
Robert Kyriakis
committed
Ask every time, if user wants to delete a tag or branch on a remote, when exists there
1 parent 12d4008 commit 0c05990

File tree

3 files changed

+21
-113
lines changed

3 files changed

+21
-113
lines changed

PBCloneRepositoryPanel.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ + (id) panel
3636

3737
+ (void)beginCloneRepository:(NSString *)repository toURL:(NSURL *)targetURL isBare:(BOOL)bare
3838
{
39-
if (!repository || [repository isEqualToString:@""] || !targetURL || [[targetURL path] isEqualToString:@""])
39+
if ((!repository) || [repository isEqualToString:@""] || (!targetURL) || [[targetURL path] isEqualToString:@""])
4040
return;
4141

4242
PBCloneRepositoryPanel *clonePanel = [PBCloneRepositoryPanel panel];

PBGitRepository.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,8 @@ dispatch_queue_t PBGetWorkQueue();
6262
BOOL didCheckBareRepository;
6363
BOOL bareRepository;
6464
NSString* workingDirectory;
65-
66-
PBGitRef *actRef;
6765
}
66+
6867
@property (nonatomic, strong, readonly) PBStashController *stashController;
6968
@property (nonatomic, strong, readonly) PBSubmoduleController *submoduleController;
7069
@property (nonatomic, strong, readonly) PBGitResetController *resetController;

PBGitRepository.m

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

30-
#define kDialogDeleteRemoteBranch @"Delete Remote Branch"
31-
#define kDialogDeleteRemoteTag @"Delete Remote Tag"
32-
3330

3431
NSString* PBGitRepositoryErrorDomain = @"GitXErrorDomain";
3532

36-
@interface PBGitRepository()
37-
- (void)checkDeleteRemoteBranch:(PBGitRef *)ref;
38-
- (void)checkDeleteRemoteTag:(PBGitRef *)ref;
39-
@end
40-
4133
dispatch_queue_t PBGetWorkQueue() {
4234
#if 1
4335
static dispatch_queue_t work_queue;
@@ -1356,114 +1348,28 @@ - (BOOL) deleteRemote:(PBGitRef *)ref
13561348
}
13571349

13581350

1359-
- (void)checkDeleteRemoteBranch:(PBGitRef *)ref
1360-
{
1361-
if ((!ref) || (![ref isRemoteBranch]) )
1362-
{
1363-
return;
1364-
}
1365-
1366-
if (![self isRemoteConnected:ref])
1367-
{
1368-
NSString *info = [NSString stringWithFormat:@"Remote %@ is not conneted!",[ref remoteName]];
1369-
NSError *error = [NSError errorWithDomain:PBGitRepositoryErrorDomain
1370-
code:0
1371-
userInfo:[NSDictionary dictionaryWithObjectsAndKeys:
1372-
[NSString stringWithFormat:@"Can't remove the branch %@ from the remote %@",[ref remoteBranchName],[ref remoteName]], NSLocalizedDescriptionKey,
1373-
info, NSLocalizedRecoverySuggestionErrorKey,
1374-
nil]
1375-
];
1376-
[[NSAlert alertWithError:error]runModal];
1377-
return;
1378-
}
1379-
1380-
if ([PBGitDefaults isDialogWarningSuppressedForDialog:kDialogDeleteRemoteBranch]) {
1381-
[self deleteRemoteBranch:ref];
1382-
return;
1383-
}
1384-
1385-
NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:@"Delete remotebranch %@ also on remote %@?",[ref remoteBranchName],[ref remoteName] ]
1386-
defaultButton:@"Delete"
1387-
alternateButton:@"Cancel"
1388-
otherButton:nil
1389-
informativeTextWithFormat:@"Are you sure you want to remove the remotebranch %@ also on remote %@?",[ref remoteBranchName],[ref remoteName]];
1390-
[alert setShowsSuppressionButton:YES];
1391-
1392-
[alert beginSheetModalForWindow:[[self windowController] window]
1393-
modalDelegate:self
1394-
didEndSelector:@selector(checkDeleteRemoteBranchSheetDidEnd:returnCode:contextInfo:)
1395-
contextInfo:Nil];
1396-
actRef = ref;
1397-
}
1398-
1399-
1400-
- (void)checkDeleteRemoteBranchSheetDidEnd:(NSAlert *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
1401-
{
1402-
[[sheet window] orderOut:nil];
1403-
1404-
if ([[sheet suppressionButton] state] == NSOnState)
1405-
[PBGitDefaults suppressDialogWarningForDialog:kDialogDeleteRemoteBranch];
1406-
1407-
if (returnCode == NSAlertDefaultReturn) {
1408-
[self deleteRemoteBranch:actRef];
1409-
}
1410-
}
1411-
1412-
14131351
- (BOOL) deleteRemoteBranch:(PBGitRef *)ref
14141352
{
14151353
if ((!ref) || (![ref isRemoteBranch]) )
14161354
{
14171355
return NO;
14181356
}
14191357

1420-
NSArray *arguments = [NSArray arrayWithObjects:@"push", [ref remoteName], [NSString stringWithFormat:@":%@",[ref remoteBranchName]], nil];
1421-
NSString *description = [NSString stringWithFormat:@"Deleting Remotebranch %@ from remote %@",[ref remoteBranchName], [ref remoteName]];
1422-
NSString *title = @"Deleting Branch from remote";
1423-
[PBRemoteProgressSheet beginRemoteProgressSheetForArguments:arguments title:title description:description inRepository:self];
1358+
int alertRet = [[NSAlert alertWithMessageText:[NSString stringWithFormat:@"Delete branch %@ on remote %@?",[ref remoteBranchName],[ref remoteName]]
1359+
defaultButton:@"Yes"
1360+
alternateButton:@"No"
1361+
otherButton:nil
1362+
informativeTextWithFormat:[NSString stringWithFormat:@"Delete branch %@ on remote %@?",[ref remoteBranchName],[ref remoteName]]]
1363+
runModal];
14241364

1425-
[self reloadRefs];
1426-
return YES;
1427-
}
1428-
1429-
1430-
- (void)checkDeleteRemoteTag:(PBGitRef *)ref
1431-
{
1432-
if ((!ref) || (![ref isTag]) || (![self hasRemotes]) )
1365+
if (alertRet == NSAlertDefaultReturn)
14331366
{
1434-
return;
1367+
NSArray *arguments = [NSArray arrayWithObjects:@"push", [ref remoteName], [NSString stringWithFormat:@":%@",[ref remoteBranchName]], nil];
1368+
NSString *description = [NSString stringWithFormat:@"Deleting Remotebranch %@ from remote %@",[ref remoteBranchName], [ref remoteName]];
1369+
NSString *title = @"Deleting Branch from remote";
1370+
[PBRemoteProgressSheet beginRemoteProgressSheetForArguments:arguments title:title description:description inRepository:self];
14351371
}
1436-
1437-
if ([PBGitDefaults isDialogWarningSuppressedForDialog:kDialogDeleteRemoteTag]) {
1438-
[self deleteRemoteTag:ref];
1439-
return;
1440-
}
1441-
1442-
NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:@"Delete tag %@ also on remotes where exists?",[ref tagName]]
1443-
defaultButton:@"Delete"
1444-
alternateButton:@"Cancel"
1445-
otherButton:nil
1446-
informativeTextWithFormat:@"Are you sure you want to remove the tag %@ also on remotes where the tag exists?",[ref tagName]];
1447-
[alert setShowsSuppressionButton:YES];
1448-
1449-
[alert beginSheetModalForWindow:[[self windowController] window]
1450-
modalDelegate:self
1451-
didEndSelector:@selector(checkDeleteRemoteTagSheetDidEnd:returnCode:contextInfo:)
1452-
contextInfo:Nil];
1453-
actRef = ref;
1454-
}
1455-
1456-
1457-
- (void)checkDeleteRemoteTagSheetDidEnd:(NSAlert *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
1458-
{
1459-
[[sheet window] orderOut:nil];
1460-
1461-
if ([[sheet suppressionButton] state] == NSOnState)
1462-
[PBGitDefaults suppressDialogWarningForDialog:kDialogDeleteRemoteTag];
1463-
1464-
if (returnCode == NSAlertDefaultReturn) {
1465-
[self deleteRemoteTag:actRef];
1466-
}
1372+
return YES;
14671373
}
14681374

14691375

@@ -1526,15 +1432,18 @@ - (BOOL) deleteRemoteTag:(PBGitRef *)ref
15261432
informativeTextWithFormat:[NSString stringWithFormat:@"%@\n\n%@",argumentsString,output]
15271433
] runModal];
15281434
}
1435+
1436+
[self reloadRefs];
1437+
15291438
}
15301439
}
15311440
}
15321441
}
15331442

1534-
[self reloadRefs];
15351443
return YES;
15361444
}
15371445

1446+
15381447
- (BOOL) deleteRef:(PBGitRef *)ref
15391448
{
15401449
if (!ref)
@@ -1546,21 +1455,21 @@ - (BOOL) deleteRef:(PBGitRef *)ref
15461455
}
15471456
else if ([ref refishType] == kGitXRemoteBranchType)
15481457
{
1549-
[self checkDeleteRemoteBranch:ref];
1458+
[self deleteRemoteBranch:ref];
15501459
}
15511460
else if ([ref refishType] == kGitXTagType)
15521461
{
15531462
if ([self refExistsOnAnyRemote:ref])
15541463
{
1555-
[self checkDeleteRemoteTag:ref];
1464+
[self deleteRemoteTag:ref];
15561465
}
15571466
}
15581467

15591468
int retValue = 1;
15601469
NSArray *arguments = [NSArray arrayWithObjects:@"update-ref", @"-d", [ref ref], nil];
15611470
NSString * output = [self outputForArguments:arguments retValue:&retValue];
15621471
if (retValue) {
1563-
NSString *message = [NSString stringWithFormat:@"There was an error deleting the ref: %@\n\n", [ref shortName]];
1472+
NSString *message = [NSString stringWithFormat:@"There was an error deleting the %@ %@\n\n", [ref refishType], [ref shortName]];
15641473
[self.windowController showErrorSheetTitle:@"Delete ref failed!" message:message arguments:arguments output:output];
15651474
return NO;
15661475
}

0 commit comments

Comments
 (0)