File tree Expand file tree Collapse file tree 4 files changed +38
-0
lines changed Expand file tree Collapse file tree 4 files changed +38
-0
lines changed Original file line number Diff line number Diff line change 111111
112112// Add an entry to the index.
113113//
114+ // Note that this *cannot* add submodules. See -[GTSubmodule addToIndex:].
115+ //
114116// entry - The entry to add.
115117// error - The error if one occurred.
116118//
120122// Add an entry (by relative path) to the index.
121123// Will fail if the receiver's repository is nil.
122124//
125+ // Note that this *cannot* add submodules. See -[GTSubmodule addToIndex:].
126+ //
123127// file - The path (relative to the root of the repository) of the file to add.
124128// error - The error if one occurred.
125129//
Original file line number Diff line number Diff line change @@ -135,4 +135,13 @@ typedef enum {
135135// Returns whether the initialization succeeded.
136136- (BOOL )writeToParentConfigurationDestructively : (BOOL )overwrite error : (NSError **)error ;
137137
138+ // / Add the current HEAD to the parent repository's index.
139+ // /
140+ // / Note that it does *not* write the index.
141+ // /
142+ // / error - The error if one occurred.
143+ // /
144+ // / Returns whether the add was successful.
145+ - (BOOL )addToIndex : (NSError **)error ;
146+
138147@end
Original file line number Diff line number Diff line change @@ -140,6 +140,16 @@ - (BOOL)writeToParentConfigurationDestructively:(BOOL)overwrite error:(NSError *
140140 return YES ;
141141}
142142
143+ - (BOOL )addToIndex : (NSError **)error {
144+ int gitError = git_submodule_add_to_index (self.git_submodule , 0 );
145+ if (gitError != GIT_OK) {
146+ if (error != NULL ) *error = [NSError git_errorFor: gitError description: @" Failed to add submodule %@ to its parent's index." , self .name];
147+ return NO ;
148+ }
149+
150+ return YES ;
151+ }
152+
143153#pragma mark NSObject
144154
145155- (NSString *)description {
Original file line number Diff line number Diff line change 9999 expect (submodule.path ).to .equal (@" new_submodule_path" );
100100});
101101
102+ it (@" should add its HEAD to its parent's index" , ^{
103+ GTSubmodule *submodule = [repo submoduleWithName: @" Test_App" error: NULL ];
104+ expect (submodule).notTo .beNil ();
105+
106+ GTRepository *submoduleRepository = [[GTRepository alloc ] initWithURL: [repo.fileURL URLByAppendingPathComponent: submodule.path] error: NULL ];
107+ expect (submoduleRepository).notTo .beNil ();
108+
109+ GTCommit *commit = [submoduleRepository lookUpObjectByRevParse: @" HEAD^" error: NULL ];
110+ BOOL success = [submoduleRepository checkoutCommit: commit strategy: GTCheckoutStrategyForce error: NULL progressBlock: nil ];
111+ expect (success).to .beTruthy ();
112+
113+ success = [submodule addToIndex: NULL ];
114+ expect (success).to .beTruthy ();
115+ });
116+
102117describe (@" clean, checked out submodule" , ^{
103118 __block GTSubmodule *submodule;
104119
You can’t perform that action at this time.
0 commit comments