Skip to content

Commit 4982d37

Browse files
committed
Merge pull request libgit2#290 from libgit2/removal-by-path
Add removal by path.
2 parents c783cfa + 1ca4608 commit 4982d37

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

Classes/GTIndex.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
// Returns YES if successful, NO otherwise.
109109
- (BOOL)addEntry:(GTIndexEntry *)entry error:(NSError **)error;
110110

111-
// Add an entry by path to the index.
111+
// Add an entry (by relative path) to the index.
112112
// Will fail if the receiver's repository is nil.
113113
//
114114
// file - The path (relative to the root of the repository) of the file to add.
@@ -117,6 +117,16 @@
117117
// Returns YES if successful, NO otherwise.
118118
- (BOOL)addFile:(NSString *)file error:(NSError **)error;
119119

120+
// Remove an entry (by relative path) from the index.
121+
// Will fail if the receiver's repository is nil.
122+
//
123+
// file - The path (relative to the root of the repository) of the file to
124+
// remove.
125+
// error - The error, if one occurred.
126+
//
127+
// Returns YES if successful, NO otherwise.
128+
- (BOOL)removeFile:(NSString *)file error:(NSError **)error;
129+
120130
// Write the index to the repository.
121131
// Will fail if the receiver's repository is nil.
122132
//

Classes/GTIndex.m

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ - (GTIndexEntry *)entryWithName:(NSString *)name {
120120

121121
- (GTIndexEntry *)entryWithName:(NSString *)name error:(NSError **)error {
122122
size_t pos = 0;
123-
int gitError = git_index_find(&pos, self.git_index, name.UTF8String);
123+
int gitError = git_index_find(&pos, self.git_index, name.fileSystemRepresentation);
124124
if (gitError != GIT_OK) {
125125
if (error != NULL) *error = [NSError git_errorFor:gitError description:@"%@ not found in index", name];
126126
return NULL;
@@ -139,7 +139,7 @@ - (BOOL)addEntry:(GTIndexEntry *)entry error:(NSError **)error {
139139
}
140140

141141
- (BOOL)addFile:(NSString *)file error:(NSError **)error {
142-
int status = git_index_add_bypath(self.git_index, file.UTF8String);
142+
int status = git_index_add_bypath(self.git_index, file.fileSystemRepresentation);
143143
if (status != GIT_OK) {
144144
if (error != NULL) *error = [NSError git_errorFor:status description:@"Failed to add file %@ to index.", file];
145145
return NO;
@@ -148,6 +148,16 @@ - (BOOL)addFile:(NSString *)file error:(NSError **)error {
148148
return YES;
149149
}
150150

151+
- (BOOL)removeFile:(NSString *)file error:(NSError **)error {
152+
int status = git_index_remove_bypath(self.git_index, file.fileSystemRepresentation);
153+
if (status != GIT_OK) {
154+
if (error != NULL) *error = [NSError git_errorFor:status description:@"Failed to remove file %@ from index.", file];
155+
return NO;
156+
}
157+
158+
return YES;
159+
}
160+
151161
- (BOOL)write:(NSError **)error {
152162
int status = git_index_write(self.git_index);
153163
if (status != GIT_OK) {

0 commit comments

Comments
 (0)