-
Notifications
You must be signed in to change notification settings - Fork 281
Added -resetPathspecs:... #351
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d0748e7
Added -resetPaths:... and moved -resetToCommit:...
joshaber 479abfd
Added a test.
joshaber 99a4ecd
Moved GTRepositoryResetType.
joshaber d3377d1
Pathspecs, not paths.
joshaber a568f36
APIs and such.
joshaber 4d90953
What even are tabs.
joshaber 639e30f
Moved the test to live with the other reset test.
joshaber 8b1d9dc
I'm fed up with this world.
joshaber File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// GTRepository+Reset.h | ||
// ObjectiveGitFramework | ||
// | ||
// Created by Josh Abernathy on 4/4/14. | ||
// Copyright (c) 2014 GitHub, Inc. All rights reserved. | ||
// | ||
|
||
#import "GTRepository.h" | ||
|
||
/// The reset types. See the libgit2 documentation for more info. | ||
typedef enum { | ||
GTRepositoryResetTypeSoft = GIT_RESET_SOFT, | ||
GTRepositoryResetTypeMixed = GIT_RESET_MIXED, | ||
GTRepositoryResetTypeHard = GIT_RESET_HARD, | ||
} GTRepositoryResetType; | ||
|
||
@interface GTRepository (Reset) | ||
|
||
/// Reset the repository's HEAD to the given commit. | ||
/// | ||
/// commit - The commit the HEAD is to be reset to. Must not be nil. | ||
/// resetType - The type of reset to be used. | ||
/// error - The error if one occurred. | ||
/// | ||
/// Returns whether the reset was succcessful. | ||
- (BOOL)resetToCommit:(GTCommit *)commit resetType:(GTRepositoryResetType)resetType error:(NSError **)error; | ||
|
||
/// Resets the given pathspecs in the index to the tree entries from the commit. | ||
/// | ||
/// pathspecs - The pathspecs to reset. Cannot be nil. | ||
/// commit - The commit whose tree should be used to reset. Cannot be nil. | ||
/// error - The error if one occurred. | ||
/// | ||
/// Returns whether the reset was successful. | ||
- (BOOL)resetPathspecs:(NSArray *)pathspecs toCommit:(GTCommit *)commit error:(NSError **)error; | ||
|
||
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// | ||
// GTRepository+Reset.m | ||
// ObjectiveGitFramework | ||
// | ||
// Created by Josh Abernathy on 4/4/14. | ||
// Copyright (c) 2014 GitHub, Inc. All rights reserved. | ||
// | ||
|
||
#import "GTRepository+Reset.h" | ||
#import "GTCommit.h" | ||
#import "NSArray+StringArray.h" | ||
#import "NSError+Git.h" | ||
#import "GTSignature.h" | ||
|
||
@implementation GTRepository (Reset) | ||
|
||
- (BOOL)resetToCommit:(GTCommit *)commit resetType:(GTRepositoryResetType)resetType error:(NSError **)error { | ||
NSParameterAssert(commit != nil); | ||
|
||
int gitError = git_reset(self.git_repository, commit.git_object, (git_reset_t)resetType, (git_signature *)[self userSignatureForNow].git_signature, NULL); | ||
if (gitError != GIT_OK) { | ||
if (error != NULL) { | ||
*error = [NSError git_errorFor:gitError description:@"Failed to reset repository to commit %@.", commit.SHA]; | ||
} | ||
|
||
return NO; | ||
} | ||
|
||
return YES; | ||
} | ||
|
||
- (BOOL)resetPathspecs:(NSArray *)paths toCommit:(GTCommit *)commit error:(NSError **)error { | ||
NSParameterAssert(paths != nil); | ||
NSParameterAssert(commit != nil); | ||
|
||
git_strarray array = paths.git_strarray; | ||
int gitError = git_reset_default(self.git_repository, commit.git_object, &array); | ||
if (gitError != GIT_OK) { | ||
if (error != NULL) { | ||
*error = [NSError git_errorFor:gitError description:@"Failed resetting paths (%@) to %@", paths, commit]; | ||
} | ||
|
||
return NO; | ||
} | ||
|
||
return YES; | ||
} | ||
|
||
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// | ||
// GTRepositoryResetSpec.m | ||
// ObjectiveGitFramework | ||
// | ||
// Created by Josh Abernathy on 4/7/14. | ||
// Copyright (c) 2014 GitHub, Inc. All rights reserved. | ||
// | ||
|
||
#import "GTRepository+Reset.h" | ||
#import "GTRepository.h" | ||
#import "GTIndex.h" | ||
|
||
SpecBegin(GTRepositoryReset) | ||
|
||
__block GTRepository *repository; | ||
|
||
describe(@"-resetPathspecs:toCommit:error:", ^{ | ||
__block NSUInteger (^countStagedFiles)(void); | ||
|
||
beforeEach(^{ | ||
repository = [self testAppFixtureRepository]; | ||
|
||
countStagedFiles = ^{ | ||
__block NSUInteger count = 0; | ||
[repository enumerateFileStatusWithOptions:nil error:NULL usingBlock:^(GTStatusDelta *headToIndex, GTStatusDelta *indexToWorkingDirectory, BOOL *stop) { | ||
if (headToIndex.status != GTStatusDeltaStatusUnmodified) count++; | ||
}]; | ||
|
||
return count; | ||
}; | ||
}); | ||
|
||
it(@"should reset the path's index entry", ^{ | ||
static NSString * const fileName = @"README.md"; | ||
NSURL *fileURL = [repository.fileURL URLByAppendingPathComponent:fileName]; | ||
BOOL success = [@"blahahaha" writeToURL:fileURL atomically:YES encoding:NSUTF8StringEncoding error:NULL]; | ||
expect(success).to.beTruthy(); | ||
|
||
GTIndex *index = [repository indexWithError:NULL]; | ||
expect(index).notTo.beNil(); | ||
|
||
success = [index addFile:fileName error:NULL]; | ||
expect(success).to.beTruthy(); | ||
|
||
expect(countStagedFiles()).to.equal(1); | ||
|
||
GTCommit *HEAD = [repository lookUpObjectByRevParse:@"HEAD" error:NULL]; | ||
expect(HEAD).notTo.beNil(); | ||
|
||
success = [repository resetPathspecs:@[ fileName ] toCommit:HEAD error:NULL]; | ||
expect(success).to.beTruthy(); | ||
|
||
expect(countStagedFiles()).to.equal(0); | ||
}); | ||
}); | ||
|
||
describe(@"-resetToCommit:resetType:error:", ^{ | ||
beforeEach(^{ | ||
repository = [self bareFixtureRepository]; | ||
}); | ||
|
||
it(@"should move HEAD when used", ^{ | ||
NSError *error = nil; | ||
GTReference *originalHead = [repository headReferenceWithError:NULL]; | ||
NSString *resetTargetSHA = @"8496071c1b46c854b31185ea97743be6a8774479"; | ||
|
||
GTCommit *commit = [repository lookUpObjectBySHA:resetTargetSHA error:NULL]; | ||
expect(commit).notTo.beNil(); | ||
GTCommit *originalHeadCommit = [repository lookUpObjectBySHA:originalHead.targetSHA error:NULL]; | ||
expect(originalHeadCommit).notTo.beNil(); | ||
|
||
BOOL success = [repository resetToCommit:commit resetType:GTRepositoryResetTypeSoft error:&error]; | ||
expect(success).to.beTruthy(); | ||
expect(error).to.beNil(); | ||
|
||
GTReference *head = [repository headReferenceWithError:&error]; | ||
expect(head).notTo.beNil(); | ||
expect(head.targetSHA).to.equal(resetTargetSHA); | ||
|
||
success = [repository resetToCommit:originalHeadCommit resetType:GTRepositoryResetTypeSoft error:&error]; | ||
expect(success).to.beTruthy(); | ||
expect(error).to.beNil(); | ||
|
||
head = [repository headReferenceWithError:&error]; | ||
expect(head.targetSHA).to.equal(originalHead.targetSHA); | ||
}); | ||
}); | ||
|
||
SpecEnd |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weird indentation afoot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're afoot.