Feature: reset current branch to here

This commit is contained in:
Leszek Ślażyński
2011-03-14 01:51:36 +01:00
committed by German Laullon
parent 00bb148d72
commit f47fd3c696
9 changed files with 1248 additions and 33 deletions
+3 -1
View File
@@ -7,8 +7,10 @@
//
#import <Cocoa/Cocoa.h>
#import "PBResetSheet.h"
@class PBGitRepository;
@protocol PBGitRefish;
@interface PBGitResetController : NSObject {
PBGitRepository *repository;
@@ -17,8 +19,8 @@
- (NSArray *) menuItems;
// actions
- (void) resetToRefish: (id<PBGitRefish>) spec type: (PBResetType) type;
- (void) resetHardToHead;
@end
+7 -32
View File
@@ -9,8 +9,9 @@
#import "PBGitResetController.h"
#import "PBGitRepository.h"
#import "PBCommand.h"
#import "PBGitRefish.h"
#import "PBResetSheet.h"
static NSString * const kCommandKey = @"command";
@implementation PBGitResetController
@@ -22,23 +23,11 @@ static NSString * const kCommandKey = @"command";
}
- (void) resetHardToHead {
NSAlert *alert = [NSAlert alertWithMessageText:@"Reseting working copy and index"
defaultButton:@"Cancel"
alternateButton:nil
otherButton:@"Reset"
informativeTextWithFormat:@"Are you sure you want to reset your working copy and index? All changes to them will be gone!"];
NSArray *arguments = [NSArray arrayWithObjects:@"reset", @"--hard", @"HEAD", nil];
PBCommand *cmd = [[PBCommand alloc] initWithDisplayName:@"Reset hard to HEAD" parameters:arguments repository:repository];
cmd.commandTitle = cmd.displayName;
cmd.commandDescription = @"Reseting head";
NSMutableDictionary *info = [NSMutableDictionary dictionaryWithObject:cmd forKey:kCommandKey];
[alert beginSheetModalForWindow:[repository.windowController window]
modalDelegate:self
didEndSelector:@selector(confirmResetSheetDidEnd:returnCode:contextInfo:)
contextInfo:info];
[self resetToRefish: [PBGitRef refFromString: @"HEAD"] type: PBResetTypeHard];
}
- (void) resetToRefish:(id<PBGitRefish>) refish type:(PBResetType)type {
[PBResetSheet beginResetSheetForRepository: repository refish: refish andType: type];
}
- (void) reset {
@@ -70,18 +59,4 @@ static NSString * const kCommandKey = @"command";
[super dealloc];
}
#pragma mark -
#pragma mark Confirm Window
- (void) confirmResetSheetDidEnd:(NSAlert *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
{
[[sheet window] orderOut:nil];
if (returnCode != NSAlertDefaultReturn) {
PBCommand *cmd = [(NSDictionary *)contextInfo objectForKey:kCommandKey];
[cmd invoke];
}
}
@end
+10
View File
@@ -72,6 +72,8 @@
47DBDBCA0E95016F00671A1E /* PBNSURLPathUserDefaultsTransfomer.m in Sources */ = {isa = PBXBuildFile; fileRef = 47DBDBC90E95016F00671A1E /* PBNSURLPathUserDefaultsTransfomer.m */; };
551BF11E112F376C00265053 /* gitx_askpasswd_main.m in Sources */ = {isa = PBXBuildFile; fileRef = 551BF11D112F376C00265053 /* gitx_askpasswd_main.m */; };
551BF176112F3F4B00265053 /* gitx_askpasswd in Resources */ = {isa = PBXBuildFile; fileRef = 551BF111112F371800265053 /* gitx_askpasswd */; };
65D58BC4132D27A8003F7290 /* PBResetSheet.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65D58BC3132D27A7003F7290 /* PBResetSheet.xib */; };
65D58BC7132D48C2003F7290 /* PBResetSheet.m in Sources */ = {isa = PBXBuildFile; fileRef = 65D58BC6132D48C0003F7290 /* PBResetSheet.m */; };
770B37ED0679A11B001EADE2 /* GitTest_DataModel.xcdatamodel in Sources */ = {isa = PBXBuildFile; fileRef = 770B37EC0679A11B001EADE2 /* GitTest_DataModel.xcdatamodel */; };
77C8280E06725ACE000B614F /* ApplicationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 77C8280C06725ACE000B614F /* ApplicationController.m */; };
8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; };
@@ -365,6 +367,9 @@
47DBDBC90E95016F00671A1E /* PBNSURLPathUserDefaultsTransfomer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBNSURLPathUserDefaultsTransfomer.m; sourceTree = "<group>"; };
551BF111112F371800265053 /* gitx_askpasswd */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = gitx_askpasswd; sourceTree = BUILT_PRODUCTS_DIR; };
551BF11D112F376C00265053 /* gitx_askpasswd_main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = gitx_askpasswd_main.m; sourceTree = "<group>"; };
65D58BC3132D27A7003F7290 /* PBResetSheet.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = PBResetSheet.xib; sourceTree = "<group>"; };
65D58BC5132D48BF003F7290 /* PBResetSheet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBResetSheet.h; sourceTree = "<group>"; };
65D58BC6132D48C0003F7290 /* PBResetSheet.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBResetSheet.m; sourceTree = "<group>"; };
770B37EC0679A11B001EADE2 /* GitTest_DataModel.xcdatamodel */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = wrapper.xcdatamodel; path = GitTest_DataModel.xcdatamodel; sourceTree = "<group>"; };
77C82804067257F0000B614F /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = /System/Library/Frameworks/CoreData.framework; sourceTree = "<absolute>"; };
77C8280B06725ACE000B614F /* ApplicationController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ApplicationController.h; sourceTree = "<group>"; };
@@ -846,6 +851,7 @@
21230ED11285EB5A0046E5A1 /* PBArgumentPicker.xib */,
F58DB55F10566E3900CFDF4A /* PBGitSidebarView.xib */,
D8022FE711E124A0003C21F6 /* PBGitXMessageSheet.xib */,
65D58BC3132D27A7003F7290 /* PBResetSheet.xib */,
);
name = Resources;
sourceTree = "<group>";
@@ -937,6 +943,8 @@
D8083E02111FA33700337480 /* PBCloneRepositoryPanel.m */,
D8022FEB11E124C8003C21F6 /* PBGitXMessageSheet.h */,
D8022FEC11E124C8003C21F6 /* PBGitXMessageSheet.m */,
65D58BC5132D48BF003F7290 /* PBResetSheet.h */,
65D58BC6132D48C0003F7290 /* PBResetSheet.m */,
);
name = Sheets;
sourceTree = "<group>";
@@ -1437,6 +1445,7 @@
31DAA7ED1317737100463846 /* gitx_l_pub.pem in Resources */,
316E7202131EE9C600AFBB36 /* list_Template.png in Resources */,
316E7203131EE9C600AFBB36 /* sidebar_Template.png in Resources */,
65D58BC4132D27A8003F7290 /* PBResetSheet.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1606,6 +1615,7 @@
217FF0BA12A1CB3300785A65 /* PBSubmoduleController.m in Sources */,
217FF0BB12A1CB3300785A65 /* PBGitResetController.m in Sources */,
217FF0BE12A1CB3E00785A65 /* PBRevealWithFinderCommand.m in Sources */,
65D58BC7132D48C2003F7290 /* PBResetSheet.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
+1
View File
@@ -31,6 +31,7 @@
- (void) showConfirmPushRefSheet:(PBGitRef *)ref remote:(PBGitRef *)remoteRef;
- (void) checkout:(PBRefMenuItem *)sender;
- (void) reset:(PBRefMenuItem *)sender;
- (void) merge:(PBRefMenuItem *)sender;
- (void) cherryPick:(PBRefMenuItem *)sender;
- (void) rebaseHeadBranch:(PBRefMenuItem *)sender;
+7
View File
@@ -149,6 +149,13 @@
[historyController.repository checkoutRefish:refish];
}
#pragma mark Reset
- (void) reset:(PBRefMenuItem *)sender
{
id <PBGitRefish> refish = [sender refish];
[historyController.repository.resetController resetToRefish: refish type: PBResetTypeMixed];
}
#pragma mark Cherry Pick
+9
View File
@@ -61,6 +61,10 @@
[items addObject:[PBRefMenuItem itemWithTitle:checkoutTitle action:@selector(checkout:) enabled:!isHead]];
[items addObject:[PBRefMenuItem separatorItem]];
NSString *resetTitle = [NSString stringWithFormat:@"Reset %@ to %@", headRefName, targetRefName];
[items addObject:[PBRefMenuItem itemWithTitle: resetTitle action:@selector(reset:) enabled:YES]];
[items addObject:[PBRefMenuItem separatorItem]];
// create branch
NSString *createBranchTitle = [ref isRemoteBranch] ? [NSString stringWithFormat:@"Create branch that tracks %@…", targetRefName] : @"Create branch…";
[items addObject:[PBRefMenuItem itemWithTitle:createBranchTitle action:@selector(createBranch:) enabled:YES]];
@@ -156,7 +160,12 @@
[items addObject:[PBRefMenuItem itemWithTitle:@"Checkout Commit" action:@selector(checkout:) enabled:YES]];
[items addObject:[PBRefMenuItem separatorItem]];
NSString *resetTitle = [NSString stringWithFormat:@"Reset %@ to here", headBranchName];
[items addObject:[PBRefMenuItem itemWithTitle: resetTitle action:@selector(reset:) enabled:YES]];
[items addObject:[PBRefMenuItem separatorItem]];
[items addObject:[PBRefMenuItem itemWithTitle:@"Create Branch…" action:@selector(createBranch:) enabled:YES]];
[items addObject:[PBRefMenuItem itemWithTitle:@"Create Tag…" action:@selector(createTag:) enabled:YES]];
[items addObject:[PBRefMenuItem separatorItem]];
+35
View File
@@ -0,0 +1,35 @@
//
// PBResetSheet.h
// GitX
//
// Created by Leszek Slazynski on 11-03-13.
// Copyright 2011 LSL. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@protocol PBGitRefish;
@class PBGitRepository;
typedef enum PBResetType {
PBResetTypeNone,
PBResetTypeSoft,
PBResetTypeMixed,
PBResetTypeHard,
PBResetTypeMerge,
PBResetTypeKeep
} PBResetType;
@interface PBResetSheet : NSWindowController {
IBOutlet NSSegmentedControl* resetType;
IBOutlet NSTabView* resetDesc;
PBResetType defaultType;
id<PBGitRefish> targetRefish;
PBGitRepository* repository;
}
+ (void) beginResetSheetForRepository:(PBGitRepository*) repo refish:(id<PBGitRefish>)refish andType:(PBResetType)type;
- (IBAction)resetBranch:(id)sender;
- (IBAction)cancel:(id)sender;
@end
+67
View File
@@ -0,0 +1,67 @@
//
// PBResetSheet.m
// GitX
//
// Created by Leszek Slazynski on 11-03-13.
// Copyright 2011 LSL. All rights reserved.
//
#import "PBResetSheet.h"
#import "PBGitRefish.h"
#import "PBCommand.h"
#import "PBGitRepository.h"
static const char* StringFromResetType(PBResetType type) {
static const char* resetTypes[] = {
"none", "soft", "mixed", "hard", "merge", "keep"
};
return resetTypes[type];
}
@implementation PBResetSheet
- (void) beginResetSheetForRepository:(PBGitRepository*) repo refish:(id<PBGitRefish>)refish andType:(PBResetType)type {
defaultType = type;
targetRefish = refish;
repository = repo;
[NSApp beginSheet: [self window]
modalForWindow: [[repository windowController] window]
modalDelegate: self
didEndSelector: nil
contextInfo: NULL];
}
+ (void) beginResetSheetForRepository:(PBGitRepository*) repo refish:(id<PBGitRefish>)refish andType:(PBResetType)type {
PBResetSheet* sheet = [[self alloc] initWithWindowNibName: @"PBResetSheet"];
[sheet beginResetSheetForRepository: repo refish: refish andType: type];
}
- (id) init {
if ( (self = [super initWithWindowNibName: @"PBResetSheet"]) ) {
defaultType = PBResetTypeMixed;
}
return self;
}
- (void) windowDidLoad {
[resetType setSelectedSegment: defaultType - 1];
[resetDesc selectTabViewItemAtIndex: defaultType - 1];
}
- (IBAction)resetBranch:(id)sender {
[NSApp endSheet:[self window]];
[[self window] orderOut:self];
PBResetType type = [resetType selectedSegment] + 1;
NSString* type_arg = [NSString stringWithFormat: @"--%s", StringFromResetType(type)];
NSArray *arguments = [NSArray arrayWithObjects:@"reset", type_arg, [targetRefish refishName], nil];
PBCommand *cmd = [[PBCommand alloc] initWithDisplayName:@"Reset branch" parameters:arguments repository:repository];
[cmd invoke];
}
- (IBAction)cancel:(id)sender {
[NSApp endSheet:[self window]];
[[self window] orderOut:self];
}
@end
+1109
View File
File diff suppressed because it is too large Load Diff