Skip to content

Stash support #431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
dbd4ab8
Change inconsistent "SHA" uses to "OID"
tiennou Jul 12, 2014
86b0019
Just use the ref's OID directly.
tiennou Jul 12, 2014
56cd7a6
Use URLs for locating the working directory.
tiennou Jul 15, 2014
37db497
Private ivars go in class extensions.
tiennou Jul 15, 2014
af1c4b5
Property-fy PBGitIndex.
tiennou Jul 15, 2014
e05a628
Move some common actions up in the responder chain.
tiennou Jul 15, 2014
65ebec8
Show HEAD in the sidebar if it's detached
tiennou Feb 13, 2015
73cf163
added stashes property to PBGitRepository.
muhqu Aug 1, 2013
86801cf
add Stashes list to Sidebar.
muhqu Aug 1, 2013
5e950cb
keep stashes in sidebar updated when repository changes
muhqu Aug 6, 2013
650fbd9
wire-up stash actions: pop, apply, drop
muhqu Aug 6, 2013
3fdc4a3
added "Stash Changes" button and "Keep Index" checkbox to Commit View.
muhqu Aug 7, 2013
297d345
wire-up stash save, with keep index option
muhqu Aug 7, 2013
9d0767e
make "Stash Changes" button inactive if working copy is clean.
muhqu Aug 7, 2013
4402136
out-comment too verbose logging
muhqu Aug 11, 2013
3b38652
added App Menu items under "Repository"
muhqu Aug 11, 2013
88442a1
improve keyboard navigation in commit dialog
muhqu Aug 7, 2013
8e0615a
quick and dirty show stash error messages via showErrorSheet
muhqu Aug 21, 2013
381cc3d
Missing initialization
tiennou Feb 13, 2015
ba99cf3
Cosmetics
tiennou Feb 13, 2015
8440a3b
Silence the analyzer
tiennou Feb 13, 2015
1aa7aae
Prevents refs/stash from being deleted
tiennou Feb 13, 2015
90a07b1
Workaround because the commit controller isn't part of the responder …
tiennou Feb 13, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Classes/Controllers/PBDiffWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ + (void) showDiffWindowWithFiles:(NSArray *)filePaths fromCommit:(PBGitCommit *)
if (!diffCommit)
diffCommit = [startCommit.repository headCommit];

NSString *commitSelector = [NSString stringWithFormat:@"%@..%@", [startCommit realSha], [diffCommit realSha]];
NSString *commitSelector = [NSString stringWithFormat:@"%@..%@", startCommit.SHA, diffCommit.SHA];
NSMutableArray *arguments = [NSMutableArray arrayWithObjects:@"diff", @"--no-ext-diff", commitSelector, nil];

if (![PBGitDefaults showWhitespaceDifferences])
Expand Down
15 changes: 14 additions & 1 deletion Classes/Controllers/PBGitCommitController.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,32 @@
PBGitIndex *index;

IBOutlet PBCommitMessageView *commitMessageView;

BOOL stashKeepIndex;

IBOutlet NSArrayController *unstagedFilesController;
IBOutlet NSArrayController *cachedFilesController;
IBOutlet NSArrayController *trackedFilesController;

IBOutlet NSTabView *controlsTabView;
IBOutlet NSButton *commitButton;
IBOutlet NSButton *stashButton;

IBOutlet PBGitIndexController *indexController;
IBOutlet PBWebChangesController *webController;
IBOutlet PBNiceSplitView *commitSplitView;
}

@property(readonly) PBGitIndex *index;
@property(assign) BOOL stashKeepIndex;

- (IBAction) refresh:(id) sender;
- (IBAction) commit:(id) sender;
- (IBAction) forceCommit:(id) sender;
- (IBAction)signOff:(id)sender;
- (IBAction) signOff:(id)sender;
- (IBAction) stashChanges:(id) sender;

- (NSView *) nextKeyViewFor:(NSView *)view;
- (NSView *) previousKeyViewFor:(NSView *)view;

@end
94 changes: 87 additions & 7 deletions Classes/Controllers/PBGitCommitController.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@
#import "PBNiceSplitView.h"
#import "PBGitRepositoryWatcher.h"
#import "PBCommitMessageView.h"
#import "PBGitIndexController.h"

#import <ObjectiveGit/GTRepository.h>
#import <ObjectiveGit/GTConfiguration.h>

#define kCommitSplitViewPositionDefault @"Commit SplitView Position"
#define kControlsTabIndexCommit 0
#define kControlsTabIndexStash 1

@interface PBGitCommitController ()
@interface PBGitCommitController () <NSTextViewDelegate>
- (void)refreshFinished:(NSNotification *)notification;
- (void)commitWithVerification:(BOOL) doVerify;
- (void)commitStatusUpdated:(NSNotification *)notification;
Expand All @@ -36,6 +39,7 @@ - (void)saveCommitSplitViewPosition;
@implementation PBGitCommitController

@synthesize index;
@synthesize stashKeepIndex;

- (id)initWithRepository:(PBGitRepository *)theRepository superController:(PBGitWindowController *)controller
{
Expand All @@ -62,11 +66,13 @@ - (void)awakeFromNib
[super awakeFromNib];

commitMessageView.repository = self.repository;
commitMessageView.delegate = self;

[commitMessageView setTypingAttributes:[NSDictionary dictionaryWithObject:[NSFont fontWithName:@"Monaco" size:12.0] forKey:NSFontAttributeName]];

[unstagedFilesController setFilterPredicate:[NSPredicate predicateWithFormat:@"hasUnstagedChanges == 1"]];
[cachedFilesController setFilterPredicate:[NSPredicate predicateWithFormat:@"hasStagedChanges == 1"]];
[trackedFilesController setFilterPredicate:[NSPredicate predicateWithFormat:@"status > 0"]];

[unstagedFilesController setSortDescriptors:[NSArray arrayWithObjects:
[[NSSortDescriptor alloc] initWithKey:@"status" ascending:false],
Expand Down Expand Up @@ -126,6 +132,8 @@ - (IBAction)signOff:(id)sender

- (void) refresh:(id) sender
{
[controlsTabView selectTabViewItemAtIndex:kControlsTabIndexCommit];

self.isBusy = YES;
self.status = @"Refreshing index…";
[index refresh];
Expand All @@ -139,6 +147,12 @@ - (void) updateView
[self refresh:nil];
}

- (IBAction) stashChanges:(id)sender
{
NSLog(@"stash changes: %@", stashKeepIndex ? @"keep index" : @"");
[self.repository stashSaveWithKeepIndex:stashKeepIndex];
}

- (IBAction) commit:(id) sender
{
[self commitWithVerification:YES];
Expand Down Expand Up @@ -229,12 +243,12 @@ - (void)indexChanged:(NSNotification *)notification
{
[cachedFilesController rearrangeObjects];
[unstagedFilesController rearrangeObjects];
if ([[cachedFilesController arrangedObjects] count]) {
[commitButton setEnabled:YES];
} else {
[commitButton setEnabled:NO];
}


NSUInteger tracked = [[trackedFilesController arrangedObjects] count];
NSUInteger staged = [[cachedFilesController arrangedObjects] count];

[commitButton setEnabled:(staged > 0)];
[stashButton setEnabled:(staged > 0 || tracked > 0)];
}

- (void)indexOperationFailed:(NSNotification *)notification
Expand Down Expand Up @@ -316,4 +330,70 @@ - (void)restoreCommitSplitViewPositiion
[commitSplitView setHidden:NO];
}

#pragma mark Handle "alt" key-down/up events
// to toggle commit/stash controls

- (void)flagsChanged:(NSEvent *)theEvent
{
BOOL altDown = !!([theEvent modifierFlags] & NSAlternateKeyMask);
int currIndex = [controlsTabView indexOfTabViewItem:controlsTabView.selectedTabViewItem];
int desiredIndex = altDown ? kControlsTabIndexStash : kControlsTabIndexCommit;
if (currIndex != desiredIndex) {
[controlsTabView selectTabViewItemAtIndex:desiredIndex];
}
}

#pragma mark NSTextView delegate methods

- (void)focusTable:(NSTableView *)table
{
if ([table numberOfRows] > 0) {
if ([table numberOfSelectedRows] == 0) {
[table selectRowIndexes:[NSIndexSet indexSetWithIndex:0] byExtendingSelection:NO];
}
[[table window] makeFirstResponder:table];
}
}

- (BOOL)textView:(NSTextView *)textView doCommandBySelector:(SEL)commandSelector;
{
if (commandSelector == @selector(insertTab:)) {
[self focusTable:indexController.stagedTable];
return YES;
} else if (commandSelector == @selector(insertBacktab:)) {
[self focusTable:indexController.unstagedTable];
return YES;
}
return NO;
}

# pragma mark Key View Chain

-(NSView *)nextKeyViewFor:(NSView *)view
{
NSView * next = nil;
if (view == indexController.unstagedTable) {
next = commitMessageView;
}
else if (view == commitMessageView) {
next = indexController.stagedTable;
}
else if (view == indexController.stagedTable) {
next = commitButton;
}
return next;
}

-(NSView *)previousKeyViewFor:(NSView *)view
{
NSView * next = nil;
if (view == indexController.stagedTable) {
next = commitMessageView;
}
else if (view == commitMessageView) {
next = indexController.unstagedTable;
}
return next;
}

@end
52 changes: 15 additions & 37 deletions Classes/Controllers/PBGitHistoryController.m
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,9 @@ - (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(
[self updateStatus];

if ([repository.currentBranch isSimpleRef])
[self selectCommit:[repository shaForRef:[repository.currentBranch ref]]];
[self selectCommit:[repository OIDForRef:repository.currentBranch.ref]];
else
[self selectCommit:[[self firstCommit] sha]];
[self selectCommit:self.firstCommit.OID];
return;
}

Expand All @@ -322,7 +322,11 @@ - (BOOL)validateMenuItem:(NSMenuItem *)menuItem
} else if ([menuItem action] == @selector(setTreeView:)) {
[menuItem setState:(self.selectedCommitDetailsIndex == kHistoryTreeViewIndex) ? NSOnState : NSOffState];
}
return YES;

if ([self respondsToSelector:[menuItem action]])
return YES;

return [[self nextResponder] validateMenuItem:menuItem];
}

- (IBAction) setDetailedView:(id)sender
Expand Down Expand Up @@ -382,7 +386,7 @@ - (void) copyCommitInfo
PBGitCommit *commit = [[commitController selectedObjects] objectAtIndex:0];
if (!commit)
return;
NSString *info = [NSString stringWithFormat:@"%@ (%@)", [[commit realSha] substringToIndex:10], [commit subject]];
NSString *info = [NSString stringWithFormat:@"%@ (%@)", [commit.SHA substringToIndex:10], commit.subject];

NSPasteboard *a =[NSPasteboard generalPasteboard];
[a declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:self];
Expand All @@ -395,7 +399,7 @@ - (void) copyCommitSHA
PBGitCommit *commit = [[commitController selectedObjects] objectAtIndex:0];
if (!commit)
return;
NSString *info = [[commit realSha] substringWithRange:NSMakeRange(0, 7)];
NSString *info = [commit.SHA substringWithRange:NSMakeRange(0, 7)];

NSPasteboard *a =[NSPasteboard generalPasteboard];
[a declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:self];
Expand Down Expand Up @@ -487,9 +491,9 @@ - (void) scrollSelectionToTopOfViewFrom:(NSInteger)oldIndex
commitList.useAdjustScroll = NO;
}

- (NSArray *) selectedObjectsForSHA:(GTOID *)commitSHA
- (NSArray *) selectedObjectsForOID:(GTOID *)commitOID
{
NSPredicate *selection = [NSPredicate predicateWithFormat:@"sha == %@", commitSHA];
NSPredicate *selection = [NSPredicate predicateWithFormat:@"OID == %@", commitOID];
NSArray *selectedCommits = [[commitController content] filteredArrayUsingPredicate:selection];

if (([selectedCommits count] == 0) && [self firstCommit])
Expand All @@ -498,14 +502,14 @@ - (NSArray *) selectedObjectsForSHA:(GTOID *)commitSHA
return selectedCommits;
}

- (void)selectCommit:(GTOID *)commitSHA
- (void)selectCommit:(GTOID *)commitOID
{
if (!forceSelectionUpdate && [[[[commitController selectedObjects] lastObject] sha] isEqual:commitSHA])
if (!forceSelectionUpdate && [[[commitController.selectedObjects lastObject] OID] isEqual:commitOID])
return;

NSInteger oldIndex = [[commitController selectionIndexes] firstIndex];

NSArray *selectedCommits = [self selectedObjectsForSHA:commitSHA];
NSArray *selectedCommits = [self selectedObjectsForOID:commitOID];
[commitController setSelectedObjects:selectedCommits];

[self scrollSelectionToTopOfViewFrom:oldIndex];
Expand Down Expand Up @@ -564,31 +568,6 @@ - (void)showCommitsFromTree:(id)sender
[searchController setHistorySearch:searchString mode:kGitXPathSearchMode];
}

- (void)showInFinderAction:(id)sender
{
NSString *workingDirectory = [[repository workingDirectory] stringByAppendingString:@"/"];
NSString *path;
NSWorkspace *ws = [NSWorkspace sharedWorkspace];

for (NSString *filePath in [sender representedObject]) {
path = [workingDirectory stringByAppendingPathComponent:filePath];
[ws selectFile: path inFileViewerRootedAtPath:path];
}

}

- (void)openFilesAction:(id)sender
{
NSString *workingDirectory = [[repository workingDirectory] stringByAppendingString:@"/"];
NSString *path;
NSWorkspace *ws = [NSWorkspace sharedWorkspace];

for (NSString *filePath in [sender representedObject]) {
path = [workingDirectory stringByAppendingPathComponent:filePath];
[ws openFile:path];
}
}

- (void) checkoutFiles:(id)sender
{
NSMutableArray *files = [NSMutableArray array];
Expand Down Expand Up @@ -627,7 +606,7 @@ - (NSArray *)menuItemsForPaths:(NSArray *)paths
PBGitRef *headRef = [[repository headRef] ref];
NSString *headRefName = [headRef shortName];
NSString *diffTitle = [NSString stringWithFormat:@"Diff %@ with %@", multiple ? @"files" : @"file", headRefName];
BOOL isHead = [[selectedCommit sha] isEqual:[repository headSHA]];
BOOL isHead = [selectedCommit.OID isEqual:repository.headOID];
NSMenuItem *diffItem = [[NSMenuItem alloc] initWithTitle:diffTitle
action:isHead ? nil : @selector(diffFilesAction:)
keyEquivalent:@""];
Expand All @@ -644,7 +623,6 @@ - (NSArray *)menuItemsForPaths:(NSArray *)paths

NSArray *menuItems = [NSArray arrayWithObjects:historyItem, diffItem, checkoutItem, finderItem, openFilesItem, nil];
for (NSMenuItem *item in menuItems) {
[item setTarget:self];
[item setRepresentedObject:filePaths];
}

Expand Down
6 changes: 6 additions & 0 deletions Classes/Controllers/PBGitIndexController.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@
IBOutlet NSTableView *stagedTable;
}

@property (readonly) NSTableView *unstagedTable;
@property (readonly) NSTableView *stagedTable;

- (IBAction) rowClicked:(NSCell *) sender;
- (IBAction) tableClicked:(NSTableView *)tableView;

- (NSMenu *) menuForTable:(NSTableView *)table;
- (NSView *) nextKeyViewFor:(NSView *)view;
- (NSView *) previousKeyViewFor:(NSView *)view;


- (void) stageSelectedFiles;
- (void) unstageSelectedFiles;
Expand Down
Loading