Skip to content

Commit 9234cce

Browse files
committed
Make writing the ignore rule more explicit.
1 parent 5b7ea0c commit 9234cce

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

ObjectiveGit/GTSubmodule.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ NS_ASSUME_NONNULL_BEGIN
6060
@property (nonatomic, strong, readonly) GTRepository *parentRepository;
6161

6262
/// The current ignore rule for this submodule.
63-
///
64-
/// Setting this property will only update the rule in memory, not on disk.
65-
@property (nonatomic, assign) GTSubmoduleIgnoreRule ignoreRule;
63+
@property (nonatomic, readonly, assign) GTSubmoduleIgnoreRule ignoreRule;
6664

6765
/// The OID that the submodule is pinned to in the parent repository's index.
6866
///
@@ -111,6 +109,16 @@ NS_ASSUME_NONNULL_BEGIN
111109
/// Returns whether reloading succeeded.
112110
- (BOOL)reload:(NSError **)error;
113111

112+
/// Write a new ignore rule to disk and get the resulting submodule. The
113+
/// receiver will not have the new ignore rule. To update the receiver, call
114+
/// `-reload:`.
115+
///
116+
/// ignoreRule - The ignore rule.
117+
/// error - The error if one occurred.
118+
///
119+
/// Returns the updated submodule or nil if an error occurred.
120+
- (GTSubmodule *)submoduleByUpdatingIgnoreRule:(GTSubmoduleIgnoreRule)ignoreRule error:(NSError **)error;
121+
114122
/// Synchronizes the submodule repository's configuration files with the settings
115123
/// from the parent repository.
116124
///

ObjectiveGit/GTSubmodule.m

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,16 @@ - (GTSubmoduleIgnoreRule)ignoreRule {
2525
return (GTSubmoduleIgnoreRule)git_submodule_ignore(self.git_submodule);
2626
}
2727

28-
- (void)setIgnoreRule:(GTSubmoduleIgnoreRule)ignoreRule {
29-
git_submodule_set_ignore(self.parentRepository.git_repository, git_submodule_name(self.git_submodule), (git_submodule_ignore_t)ignoreRule);
28+
- (GTSubmodule *)submoduleByUpdatingIgnoreRule:(GTSubmoduleIgnoreRule)ignoreRule error:(NSError **)error {
29+
int result = git_submodule_set_ignore(self.parentRepository.git_repository, git_submodule_name(self.git_submodule), (git_submodule_ignore_t)ignoreRule);
30+
if (result != GIT_OK) {
31+
if (error != NULL) {
32+
*error = [NSError git_errorFor:result description:@"Couldn't set submodule ignore rule."];
33+
}
34+
return nil;
35+
}
3036

31-
// The docs for `git_submodule_set_ignore` note "This does not affect any
32-
// currently-loaded instances." So we need to reload.
33-
git_submodule_reload(self.git_submodule, 0);
37+
return [self.parentRepository submoduleWithName:self.name error:error];
3438
}
3539

3640
- (GTOID *)indexOID {

0 commit comments

Comments
 (0)