diff --git a/Classes/GTRepository.h b/Classes/GTRepository.h index 1330c1eaa..5e456de04 100644 --- a/Classes/GTRepository.h +++ b/Classes/GTRepository.h @@ -61,6 +61,13 @@ typedef enum : git_reset_t { GTRepositoryResetTypeHard = GIT_RESET_HARD } GTRepositoryResetType; +typedef enum : git_stash_flags { + GTRepositoryStashFlagDefault = GIT_STASH_DEFAULT, + GTRepositoryStashFlagKeepIndex = GIT_STASH_KEEP_INDEX, + GTRepositoryStashFlagIncludeUntracked = GIT_STASH_INCLUDE_UNTRACKED, + GTRepositoryStashFlagIncludeIgnored = GIT_STASH_INCLUDE_IGNORED +} GTRepositoryStashFlag; + typedef void (^GTRepositoryStatusBlock)(NSURL *fileURL, GTRepositoryFileStatus status, BOOL *stop); @interface GTRepository : NSObject @@ -212,4 +219,13 @@ typedef void (^GTRepositoryStatusBlock)(NSURL *fileURL, GTRepositoryFileStatus s // Returns the signature. - (GTSignature *)userSignatureForNow; +// Stash the repository's changes. +// +// message - the message to be attributed to the item in the stash. +// stashFlag - The flag of stash to be used. +// error(out) - in the event of an error this may be set. +// +// Returns commit of the stashed changes if successful, nil in the even of an error +- (GTCommit*)stashChangesWithMessage:(NSString *)message withStashFlag:(GTRepositoryStashFlag)stashFlag error:(NSError **)error; + @end diff --git a/Classes/GTRepository.m b/Classes/GTRepository.m index 032acfeac..91032f412 100644 --- a/Classes/GTRepository.m +++ b/Classes/GTRepository.m @@ -657,4 +657,17 @@ - (GTSignature *)userSignatureForNow { return [[GTSignature alloc] initWithName:name email:email time:[NSDate date]]; } +#pragma mark Stash + +- (GTCommit*)stashChangesWithMessage:(NSString *)message withStashFlag:(GTRepositoryStashFlag)stashFlag error:(NSError **)error +{ + git_oid oid; + + git_stash_save(&oid, self.git_repository, [self userSignatureForNow].git_signature, [message cStringUsingEncoding:NSUTF8StringEncoding], stashFlag); + + GTCommit* commit = (GTCommit*)[self lookupObjectByOid:&oid error:error]; + + return commit; +} + @end