Skip to content

Wrap git_index_add_all #628

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 2 commits into from
Jun 5, 2017
Merged
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
7 changes: 7 additions & 0 deletions ObjectiveGit/GTIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@ NS_ASSUME_NONNULL_BEGIN
/// Returns whether reading the tree was successful.
- (BOOL)addContentsOfTree:(GTTree *)tree error:(NSError **)error;

/// Add all the content of the working directory to the index. Like `git add -A`
///
/// error - If not NULL, set to any error that occurs.
///
/// Returns whether the operation was successful
- (BOOL)addAll:(NSError **)error;

/// Remove an entry (by relative path) from the index.
/// Will fail if the receiver's repository is nil.
///
Expand Down
10 changes: 10 additions & 0 deletions ObjectiveGit/GTIndex.m
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,16 @@ - (BOOL)addContentsOfTree:(GTTree *)tree error:(NSError **)error {
return YES;
}

- (BOOL)addAll:(NSError **)error {
int status = git_index_add_all(self.git_index, nil, GIT_INDEX_ADD_CHECK_PATHSPEC, nil, nil);
if (status != GIT_OK) {
if (error != NULL) *error = [NSError git_errorFor:status description:@"Failed to add all the contents of the working tree to the index"];
return NO;
}

return YES;
}

- (BOOL)removeFile:(NSString *)file error:(NSError **)error {
NSString *unicodeString = [self composedUnicodeStringWithString:file];

Expand Down
27 changes: 27 additions & 0 deletions ObjectiveGitTests/GTIndexSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,33 @@
renamedFileURL = [NSURL fileURLWithPath:newPath isDirectory:NO];
});

it(@"should add all files from the current file system to the index", ^{
NSData *currentFileContent = [[NSFileManager defaultManager] contentsAtPath:fileURL.path];
expect(currentFileContent).notTo(beNil());
NSString *currentFileString = [[NSString alloc] initWithData:currentFileContent encoding:NSUTF8StringEncoding];
currentFileString = [currentFileString stringByAppendingString:@"I would like to append this to the file"];
currentFileContent = [currentFileString dataUsingEncoding:NSUTF8StringEncoding];
expect(@([[NSFileManager defaultManager] createFileAtPath:fileURL.path contents:currentFileContent attributes:nil])).to(beTruthy());

NSString *newFileContent = @"This is a new file \n1 2 3";
NSData *newFileData = [newFileContent dataUsingEncoding:NSUTF8StringEncoding];
expect(newFileData).notTo(beNil());
expect(@([[NSFileManager defaultManager] createFileAtPath:renamedFileURL.path contents:newFileData attributes:nil])).to(beTruthy());

GTIndexEntry *entry = [index entryWithPath:[filename decomposedStringWithCanonicalMapping]];
expect(@(fileStatusEqualsExpected(entry.path, GTDeltaTypeUnmodified, GTDeltaTypeModified))).to(beTruthy());
entry = [index entryWithPath:[renamedFilename decomposedStringWithCanonicalMapping]];
expect(@(fileStatusEqualsExpected(entry.path, GTDeltaTypeUnmodified, GTDeltaTypeUntracked))).to(beTruthy());

expect(@([index addAll:NULL])).to(beTruthy());
expect(@([index write:NULL])).to(beTruthy());

entry = [index entryWithPath:[filename decomposedStringWithCanonicalMapping]];
expect(@(fileStatusEqualsExpected(entry.path, GTDeltaTypeModified, GTDeltaTypeUnmodified))).to(beTruthy());
entry = [index entryWithPath:[renamedFilename decomposedStringWithCanonicalMapping]];
expect(@(fileStatusEqualsExpected(entry.path, GTDeltaTypeAdded, GTDeltaTypeUnmodified))).to(beTruthy());
});

it(@"it preserves decomposed Unicode in index paths with precomposeunicode disabled", ^{
NSString *decomposedFilename = [filename decomposedStringWithCanonicalMapping];
GTIndexEntry *entry = [index entryWithPath:decomposedFilename error:NULL];
Expand Down