Skip to content

Commit 893d420

Browse files
committed
Add push/hide HEAD/refname methods to GTEnumerator
1 parent a5642ff commit 893d420

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

ObjectiveGit/GTEnumerator.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,21 @@ NS_ASSUME_NONNULL_BEGIN
8989
/// Returns whether pushing matching references was successful.
9090
- (BOOL)pushGlob:(NSString *)refGlob error:(NSError **)error;
9191

92+
/// Push HEAD reference.
93+
///
94+
/// error - If not NULL, this will be set to any error that occurs.
95+
///
96+
/// Returns whether pushing the HEAD reference was successful.
97+
- (BOOL)pushHEAD:(NSError **)error;
98+
99+
/// Push a reference by name.
100+
///
101+
/// refName - The reference name to push. Must not be nil.
102+
/// error - If not NULL, this will be set to any error that occurs.
103+
///
104+
/// Returns whether pushing the reference name was successful.
105+
- (BOOL)pushReferenceName:(NSString *)refName error:(NSError **)error;
106+
92107
/// Hides the specified commit and all of its ancestors when enumerating.
93108
///
94109
/// sha - The SHA of a commit in the receiver's repository. This must not be
@@ -106,6 +121,22 @@ NS_ASSUME_NONNULL_BEGIN
106121
/// Returns whether marking matching references for hiding was successful.
107122
- (BOOL)hideGlob:(NSString *)refGlob error:(NSError **)error;
108123

124+
/// Hide HEAD reference.
125+
///
126+
/// error - If not NULL, this will be set to any error that occurs.
127+
///
128+
/// Returns whether marking HEAD for hiding was successful.
129+
- (BOOL)hideHEAD:(NSError **)error;
130+
131+
132+
/// Hide a reference by name.
133+
///
134+
/// refName - The reference name to hide. Must not be nil.
135+
/// error - If not NULL, this will be set to any error that occurs.
136+
///
137+
/// Returns whether hiding the reference name was successful.
138+
- (BOOL)hideReferenceName:(NSString *)refName error:(NSError **)error;
139+
109140
/// Resets the receiver, putting it back into a clean state for reuse, and
110141
/// replacing the receiver's `options`.
111142
- (void)resetWithOptions:(GTEnumeratorOptions)options;

ObjectiveGit/GTEnumerator.m

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,26 @@ - (BOOL)pushGlob:(NSString *)refGlob error:(NSError **)error {
107107
return YES;
108108
}
109109

110+
- (BOOL)pushHEAD:(NSError **)error {
111+
int gitError = git_revwalk_push_head(self.walk);
112+
if (gitError != GIT_OK) {
113+
if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Failed to push HEAD onto rev walker."];
114+
return NO;
115+
}
116+
return YES;
117+
}
118+
119+
- (BOOL)pushReferenceName:(NSString *)refName error:(NSError **)error {
120+
NSParameterAssert(refName != nil);
121+
122+
int gitError = git_revwalk_push_ref(self.walk, refName.UTF8String);
123+
if (gitError != 0) {
124+
if (error) *error = [NSError git_errorFor:gitError description:@"Failed to push reference %@", refName];
125+
return NO;
126+
}
127+
return YES;
128+
}
129+
110130
- (BOOL)hideSHA:(NSString *)sha error:(NSError **)error {
111131
NSParameterAssert(sha != nil);
112132

@@ -134,6 +154,26 @@ - (BOOL)hideGlob:(NSString *)refGlob error:(NSError **)error {
134154
return YES;
135155
}
136156

157+
- (BOOL)hideHEAD:(NSError **)error {
158+
int gitError = git_revwalk_hide_head(self.walk);
159+
if (gitError != GIT_OK) {
160+
if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Failed to hide HEAD onto rev walker."];
161+
return NO;
162+
}
163+
return YES;
164+
}
165+
166+
- (BOOL)hideReferenceName:(NSString *)refName error:(NSError **)error {
167+
NSParameterAssert(refName != nil);
168+
169+
int gitError = git_revwalk_hide_ref(self.walk, refName.UTF8String);
170+
if (gitError != 0) {
171+
if (error) *error = [NSError git_errorFor:gitError description:@"Failed to hide reference %@", refName];
172+
return NO;
173+
}
174+
return YES;
175+
}
176+
137177
#pragma mark Resetting
138178

139179
- (void)resetWithOptions:(GTEnumeratorOptions)options {

0 commit comments

Comments
 (0)