Skip to content

Commit 5ddbcd1

Browse files
committed
Disable deleting and pushing the detached HEAD
1 parent 8bb1173 commit 5ddbcd1

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

PBRefMenuItem.m

+5-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ + (NSArray *) defaultMenuItemsForRef:(PBGitRef *)ref inRepository:(PBGitReposito
4444
NSString *headRefName = [headRef shortName];
4545
BOOL isHead = [ref isEqualToRef:headRef];
4646
BOOL isOnHeadBranch = isHead ? YES : [repo isRefOnHeadBranch:ref];
47+
BOOL isDetachedHead = (isHead && [headRefName isEqualToString:@"HEAD"]);
4748

4849
NSString *remoteName = [ref remoteName];
4950
if (!remoteName && [ref isBranch])
@@ -98,6 +99,9 @@ + (NSArray *) defaultMenuItemsForRef:(PBGitRef *)ref inRepository:(PBGitReposito
9899
NSString *pushTitle = [NSString stringWithFormat:@"Push updates to %@", remoteName];
99100
[items addObject:[PBRefMenuItem itemWithTitle:pushTitle action:@selector(pushUpdatesToRemote:) enabled:YES]];
100101
}
102+
else if (isDetachedHead) {
103+
[items addObject:[PBRefMenuItem itemWithTitle:@"Push" action:nil enabled:NO]];
104+
}
101105
else {
102106
// push to default remote
103107
BOOL hasDefaultRemote = NO;
@@ -128,7 +132,7 @@ + (NSArray *) defaultMenuItemsForRef:(PBGitRef *)ref inRepository:(PBGitReposito
128132
// delete ref
129133
[items addObject:[PBRefMenuItem separatorItem]];
130134
NSString *deleteTitle = [NSString stringWithFormat:@"Delete %@", targetRefName];
131-
[items addObject:[PBRefMenuItem itemWithTitle:deleteTitle action:@selector(showDeleteRefSheet:) enabled:YES]];
135+
[items addObject:[PBRefMenuItem itemWithTitle:deleteTitle action:@selector(showDeleteRefSheet:) enabled:!isDetachedHead]];
132136

133137
for (PBRefMenuItem *item in items) {
134138
[item setTarget:target];

0 commit comments

Comments
 (0)