Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
added stashes property to PBGitRepository.
As Objective-Git doesn't yet offer stash support use libgit2 right away. should be replaced by Objective-Git equivalent when available
  • Loading branch information
muhqu authored and tiennou committed Feb 13, 2015
commit 73cf163c15b478ac4c1fcc6ea0cababc536164d6
3 changes: 3 additions & 0 deletions Classes/git/PBGitRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ extern NSString * const kGitXTagType;
extern NSString * const kGitXBranchType;
extern NSString * const kGitXRemoteType;
extern NSString * const kGitXRemoteBranchType;
extern NSString * const kGitXStashType;

extern NSString * const kGitXTagRefPrefix;
extern NSString * const kGitXBranchRefPrefix;
extern NSString * const kGitXRemoteRefPrefix;
extern NSString * const kGitXStashRefPrefix;


@interface PBGitRef : NSObject <PBGitRefish>
Expand All @@ -36,6 +38,7 @@ extern NSString * const kGitXRemoteRefPrefix;
- (BOOL) isTag;
- (BOOL) isRemote;
- (BOOL) isRemoteBranch;
- (BOOL) isStash;

- (PBGitRef *) remoteRef;

Expand Down
13 changes: 13 additions & 0 deletions Classes/git/PBGitRef.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
NSString * const kGitXBranchType = @"branch";
NSString * const kGitXRemoteType = @"remote";
NSString * const kGitXRemoteBranchType = @"remote branch";
NSString * const kGitXStashType = @"stash";

NSString * const kGitXTagRefPrefix = @"refs/tags/";
NSString * const kGitXBranchRefPrefix = @"refs/heads/";
NSString * const kGitXRemoteRefPrefix = @"refs/remotes/";
NSString * const kGitXStashRefPrefix = @"refs/stash@";

@interface PBGitRef ()

Expand Down Expand Up @@ -68,6 +70,8 @@ - (NSString *) type
return @"tag";
if ([self isRemote])
return @"remote";
if ([self isStash])
return @"stash";
return nil;
}

Expand All @@ -94,6 +98,11 @@ - (BOOL) isRemoteBranch
return ([[ref componentsSeparatedByString:@"/"] count] > 3);
}

- (BOOL) isStash
{
return [ref hasPrefix:kGitXStashRefPrefix];
}

- (BOOL) isEqualToRef:(PBGitRef *)otherRef
{
return [ref isEqualToString:[otherRef ref]];
Expand Down Expand Up @@ -141,6 +150,8 @@ - (NSString *) refishName

- (NSString *) shortName
{
if ([self isStash])
return [ref substringFromIndex:5];
if ([self type])
return [ref substringFromIndex:[[self type] length] + 7];
return ref;
Expand All @@ -156,6 +167,8 @@ - (NSString *) refishType
return kGitXRemoteBranchType;
if ([self isRemote])
return kGitXRemoteType;
if ([self isStash])
return kGitXStashType;
return nil;
}

Expand Down
3 changes: 3 additions & 0 deletions Classes/git/PBGitRepository.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
@class PBGitRevSpecifier;
@protocol PBGitRefish;
@class PBGitRef;
@class PBGitStash;
@class GTRepository;
@class GTConfiguration;

Expand Down Expand Up @@ -61,6 +62,7 @@ static NSString * PBStringFromBranchFilterType(PBGitXBranchFilterType type) {
@property (readonly, getter = getIndexURL) NSURL* indexURL;

@property (nonatomic, strong) PBGitHistoryList *revisionList;
@property (nonatomic, readonly, strong) NSArray* stashes;
@property (nonatomic, readonly, strong) NSArray* branches;
@property (nonatomic, strong) NSMutableOrderedSet* branchesSet;
@property (nonatomic, strong) PBGitRevSpecifier* currentBranch;
Expand Down Expand Up @@ -120,6 +122,7 @@ static NSString * PBStringFromBranchFilterType(PBGitXBranchFilterType type) {
- (PBGitCommit *)commitForOID:(GTOID *)sha;
- (BOOL)isOIDOnSameBranch:(GTOID *)baseOID asOID:(GTOID *)testOID;
- (BOOL)isOIDOnHeadBranch:(GTOID *)testOID;
- (PBGitStash *)stashForRef:(PBGitRef *)ref;
- (BOOL)isRefOnHeadBranch:(PBGitRef *)testRef;
- (BOOL)checkRefFormat:(NSString *)refName;
- (BOOL)refExists:(PBGitRef *)ref;
Expand Down
29 changes: 28 additions & 1 deletion Classes/git/PBGitRepository.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#import "PBGitRepositoryWatcher.h"
#import "GitRepoFinder.h"
#import "PBGitHistoryList.h"

#import "PBGitStash.h"

NSString *PBGitRepositoryDocumentType = @"Git Repository";

Expand Down Expand Up @@ -616,6 +616,33 @@ - (NSString *)workingDirectory
return [self.workingDirectoryURL path];
}

#pragma mark Stashes

- (NSArray *) stashes
{
NSMutableArray *stashes = [NSMutableArray array];
[self.gtRepo enumerateStashesUsingBlock:^(NSUInteger index, NSString *message, GTOID *oid, BOOL *stop) {
PBGitStash *stash = [[PBGitStash alloc] initWithRepository:self stashOID:oid index:index message:message];
[stashes addObject:stash];
}];
return [NSArray arrayWithArray:stashes];
}

- (PBGitStash *)stashForRef:(PBGitRef *)ref {
__block PBGitStash * found = nil;

[self.gtRepo enumerateStashesUsingBlock:^(NSUInteger index, NSString *message, GTOID *oid, BOOL *stop) {
PBGitStash *stash = [[PBGitStash alloc] initWithRepository:self stashOID:oid index:index message:message];
if ([stash.ref isEqualToRef:ref]) {
found = stash;
stop = YES;
}
}];
return found;
}



#pragma mark Remotes

- (NSArray *) remotes
Expand Down
28 changes: 28 additions & 0 deletions Classes/git/PBGitSVStashItem.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// PBSourceViewStash.m
// GitX
//
// Created by Mathias Leppich on 8/1/13.
//
//

#import "PBGitSVStashItem.h"
#import "PBGitRevSpecifier.h"


@implementation PBGitSVStashItem

+ (id)itemWithStash:(PBGitStash *)stash
{
NSString * title = [NSString stringWithFormat:@"@{%zd}: %@", stash.index, stash.message];
PBGitSVStashItem * item = [self itemWithTitle:title];
item.stash = stash;
item.revSpecifier = [[PBGitRevSpecifier alloc] initWithRef:stash.ref];
return item;
}

-(PBGitRef *)ref {
return self.stash.ref;
}

@end
27 changes: 27 additions & 0 deletions Classes/git/PBGitStash.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// PBGitStash.h
// GitX
//
// Created by Mathias Leppich on 8/1/13.
//
//

#import <Foundation/Foundation.h>
#import <ObjectiveGit/ObjectiveGit.h>

@class PBGitCommit;
@class PBGitRef;
@class PBGitRepository;

@interface PBGitStash : NSObject
@property (nonatomic, readonly) size_t index;
@property (nonatomic, readonly) PBGitCommit * commit;
@property (nonatomic, readonly) NSString* message;
@property (nonatomic, readonly) PBGitRef* ref;

@property (nonatomic, readonly) PBGitCommit * indexCommit;
@property (nonatomic, readonly) PBGitCommit * ancestorCommit;

- (id) initWithRepository:(PBGitRepository *)repo stashOID:(GTOID *)stashOID index:(NSInteger)index message:(NSString *)message;

@end
47 changes: 47 additions & 0 deletions Classes/git/PBGitStash.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// PBGitStash.m
// GitX
//
// Created by Mathias Leppich on 8/1/13.
//
//

#import "PBGitStash.h"
#import "PBGitRef.h"
#import "PBGitCommit.h"
#import "PBGitRepository.h"

@implementation PBGitStash

-(id)initWithRepository:(PBGitRepository *)repo stashOID:(GTOID *)stashOID index:(NSInteger)index message:(NSString *)message
{
_index = index;
_message = message;

GTRepository * gtRepo = repo.gtRepo;
NSError * error = nil;
GTCommit * gtCommit = (GTCommit *)[gtRepo lookUpObjectByOID:stashOID objectType:GTObjectTypeCommit error:&error];
NSArray * parents = [gtCommit parents];
GTCommit * gtIndexCommit = [parents objectAtIndex:1];
GTCommit * gtAncestorCommit = [parents objectAtIndex:0];

_commit = [[PBGitCommit alloc] initWithRepository:repo andCommit:gtCommit];
_indexCommit = [[PBGitCommit alloc] initWithRepository:repo andCommit:gtIndexCommit];
_ancestorCommit = [[PBGitCommit alloc] initWithRepository:repo andCommit:gtAncestorCommit];

NSLog(@" stash: %zd, %@, %@, %@",_index,[_commit shortName], [_ancestorCommit shortName], [_indexCommit shortName]);
return self;
}

-(NSString *)description
{
return [NSString stringWithFormat:@"stash@{%zd}: %@", _index, _message];
}

-(PBGitRef *)ref
{
NSString * refStr = [NSString stringWithFormat:@"refs/stash@{%zd}", _index];
return [[PBGitRef alloc] initWithString:refStr];
}

@end
8 changes: 8 additions & 0 deletions GitX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@
97CF01F918A6C5BB00E30F2B /* deleted_file.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 97CF01F618A6C5BB00E30F2B /* deleted_file.pdf */; };
97CF01FA18A6C5BB00E30F2B /* empty_file.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 97CF01F718A6C5BB00E30F2B /* empty_file.pdf */; };
97CF01FB18A6C5BB00E30F2B /* new_file.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 97CF01F818A6C5BB00E30F2B /* new_file.pdf */; };
A2F8D0DF17AAB32500580B84 /* PBGitStash.m in Sources */ = {isa = PBXBuildFile; fileRef = A2F8D0DE17AAB32500580B84 /* PBGitStash.m */; };
D87127011229A21C00012334 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D87127001229A21C00012334 /* QuartzCore.framework */; };
D89E9B141218BA260097A90B /* ScriptingBridge.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D89E9AB21218A9DA0097A90B /* ScriptingBridge.framework */; };
D8E3B2B810DC9FB2001096A3 /* ScriptingBridge.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D8E3B2B710DC9FB2001096A3 /* ScriptingBridge.framework */; };
Expand Down Expand Up @@ -563,6 +564,8 @@
97CF01F618A6C5BB00E30F2B /* deleted_file.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = deleted_file.pdf; sourceTree = "<group>"; };
97CF01F718A6C5BB00E30F2B /* empty_file.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = empty_file.pdf; sourceTree = "<group>"; };
97CF01F818A6C5BB00E30F2B /* new_file.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = new_file.pdf; sourceTree = "<group>"; };
A2F8D0DD17AAB32500580B84 /* PBGitStash.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBGitStash.h; sourceTree = "<group>"; };
A2F8D0DE17AAB32500580B84 /* PBGitStash.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBGitStash.m; sourceTree = "<group>"; };
D87127001229A21C00012334 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
D89E9AB21218A9DA0097A90B /* ScriptingBridge.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ScriptingBridge.framework; path = System/Library/Frameworks/ScriptingBridge.framework; sourceTree = SDKROOT; };
D8E3B2B710DC9FB2001096A3 /* ScriptingBridge.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ScriptingBridge.framework; path = /System/Library/Frameworks/ScriptingBridge.framework; sourceTree = "<absolute>"; };
Expand Down Expand Up @@ -903,6 +906,10 @@
4A5D768214A9A9CC00DF6C68 /* PBGitXErrors.m */,
4A5D768314A9A9CC00DF6C68 /* PBGitXProtocol.h */,
4A5D768414A9A9CC00DF6C68 /* PBGitXProtocol.m */,
643952721603E9BC00BB7AFF /* PBGitSubmodule.h */,
643952731603E9BC00BB7AFF /* PBGitSubmodule.m */,
A2F8D0DD17AAB32500580B84 /* PBGitStash.h */,
A2F8D0DE17AAB32500580B84 /* PBGitStash.m */,
643952751603EF9B00BB7AFF /* PBGitSVSubmoduleItem.h */,
643952761603EF9B00BB7AFF /* PBGitSVSubmoduleItem.m */,
4AB057E11652652000DE751D /* GitRepoFinder.h */,
Expand Down Expand Up @@ -1397,6 +1404,7 @@
643952771603EF9B00BB7AFF /* PBGitSVSubmoduleItem.m in Sources */,
4AB057E31652652000DE751D /* GitRepoFinder.m in Sources */,
4A2125A417C0C78A00B5B582 /* NSColor+RGB.m in Sources */,
A2F8D0DF17AAB32500580B84 /* PBGitStash.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down