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

Skip to content

Added stash command #163

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 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 16 additions & 0 deletions Classes/GTRepository.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <GTObject>
Expand Down Expand Up @@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please format these into TomDoc style by aligning the dashes and removing the (out)?

I know the existing code in this file contradicts this (it's kind of a Frankenstein right now), but +cloneFromURL:toWorkingDirectory:… is a great example of the correct style.

//
// 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
13 changes: 13 additions & 0 deletions Classes/GTRepository.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add some error checking here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cStringUsingEncoding:NSUTF8StringEncoding can be replaced with UTF8String.


GTCommit* commit = (GTCommit*)[self lookupObjectByOid:&oid error:error];

return commit;
}

@end