Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
objective-git/ObjectiveGit/GTReference.m at master · libgit2/objective-git · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
See all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
libgit2
objective-git
Repository navigation
Code
Issues
27
(27)
Pull requests
10
(10)
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
objective-git
/
ObjectiveGit
/
GTReference.m
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
259 lines (201 loc) · 7.51 KB
master
Breadcrumbs
objective-git
/
ObjectiveGit
/
GTReference.m
Copy path
Top
File metadata and controls
Code
Blame
259 lines (201 loc) · 7.51 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
//
//
GTReference.m
//
ObjectiveGitFramework
//
//
Created by Timothy Clem on 3/2/11.
//
//
Permission is hereby granted, free of charge, to any person obtaining a copy
//
of this software and associated documentation files (the "Software"), to deal
//
in the Software without restriction, including without limitation the rights
//
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//
copies of the Software, and to permit persons to whom the Software is
//
furnished to do so, subject to the following conditions:
//
//
The above copyright notice and this permission notice shall be included in
//
all copies or substantial portions of the Software.
//
//
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//
THE SOFTWARE.
//
#
import
"
GTReference.h
"
#
import
"
GTOID.h
"
#
import
"
GTReflog+Private.h
"
#
import
"
GTRepository+Private.h
"
#
import
"
GTRepository.h
"
#
import
"
GTSignature.h
"
#
import
"
NSError+Git.h
"
#
import
"
NSString+Git.h
"
#
import
"
GTRepository+References.h
"
#
import
"
git2/errors.h
"
@interface
GTReference
()
@property
(
nonatomic
,
readonly
,
assign
) git_reference *git_reference;
@end
static
NSString
*
referenceTypeToString
(GTReferenceType type) {
switch
(type) {
case
GTReferenceTypeInvalid:
return
@"
invalid
"
;
case
GTReferenceTypeDirect:
return
@"
direct
"
;
case
GTReferenceTypeSymbolic:
return
@"
symbolic
"
;
}
return
@"
unknown
"
;
}
@implementation
GTReference
- (
void
)
dealloc
{
if
(_git_reference !=
NULL
) {
git_reference_free
(_git_reference);
_git_reference =
NULL
;
}
}
#
pragma mark
API
- (
BOOL
)
isRemote
{
return
git_reference_is_remote
(self.
git_reference
) !=
0
;
}
+ (
instancetype
)
referenceByResolvingSymbolicReference
:
(GTReference *)
symbolicRef
error
:
(
NSError
**)
error
{
return
[[
self
alloc
]
initByResolvingSymbolicReference:
symbolicRef
error:
error];
}
- (
instancetype
)
init
{
NSAssert
(
NO
,
@"
Call to an unavailable initializer.
"
);
return
nil
;
}
- (
instancetype
)
initByResolvingSymbolicReference
:
(GTReference *)
symbolicRef
error
:
(
NSError
**)
error
{
NSParameterAssert
(symbolicRef !=
nil
);
git_reference *ref =
NULL
;
int
gitError =
git_reference_resolve
(&ref, symbolicRef.
git_reference
);
if
(gitError !=
GIT_OK
) {
if
(error !=
NULL
) *error = [
NSError
git_errorFor:
gitError
description:
@"
Failed to resolve reference
%@
.
"
, symbolicRef.name];
return
nil
;
}
return
[
self
initWithGitReference:
ref
repository:
symbolicRef.repository];
}
- (
instancetype
)
initWithGitReference
:
(git_reference *)
ref
repository
:
(GTRepository *)
repo
{
NSParameterAssert
(ref !=
NULL
);
NSParameterAssert
(repo !=
nil
);
self = [
super
init
];
if
(self ==
nil
)
return
nil
;
_git_reference = ref;
_repository = repo;
return
self;
}
- (
BOOL
)
isBranch
{
return
git_reference_is_branch
(self.
git_reference
) !=
0
;
}
- (
BOOL
)
isTag
{
return
git_reference_is_tag
(self.
git_reference
) !=
0
;
}
- (
BOOL
)
isNote
{
return
git_reference_is_note
(self.
git_reference
) !=
0
;
}
- (
NSString
*)
name
{
const
char
*cRefName =
git_reference_name
(self.
git_reference
);
NSAssert
(cRefName !=
nil
,
@"
Unexpected nil name
"
);
NSString
*refName = @(cRefName);
NSAssert
(refName,
@"
refname is nil
"
);
return
refName;
}
- (GTReference *)
referenceByRenaming
:
(
NSString
*)
newName
error
:
(
NSError
**)
error
{
NSParameterAssert
(newName !=
nil
);
git_reference *newRef =
NULL
;
int
gitError =
git_reference_rename
(&newRef, self.
git_reference
, newName.
UTF8String
,
0
,
NULL
);
if
(gitError !=
GIT_OK
) {
if
(error !=
NULL
) *error = [
NSError
git_errorFor:
gitError
description:
@"
Failed to rename reference
%@
to
%@
.
"
,
self
.name, newName];
return
nil
;
}
return
[[
self
.class
alloc
]
initWithGitReference:
newRef
repository:
self
.repository];
}
- (GTReferenceType)
referenceType
{
return
(GTReferenceType)
git_reference_type
(self.
git_reference
);
}
- (
id
)
unresolvedTarget
{
if
(self.
referenceType
== GTReferenceTypeDirect) {
const
git_oid *oid =
git_reference_target
(self.
git_reference
);
if
(oid ==
NULL
)
return
nil
;
return
[
self
.repository
lookUpObjectByGitOid:
oid
error:
NULL
];
}
else
if
(self.
referenceType
== GTReferenceTypeSymbolic) {
NSString
*refName = @(
git_reference_symbolic_target
(self.
git_reference
));
if
(refName ==
NULL
)
return
nil
;
return
[
self
.repository
lookUpReferenceWithName:
refName
error:
NULL
];
}
return
nil
;
}
- (
id
)
resolvedTarget
{
git_object *obj;
if
(
git_reference_peel
(&obj, self.
git_reference
,
GIT_OBJECT_ANY
) !=
GIT_OK
) {
return
nil
;
}
return
[GTObject
objectWithObj:
obj
inRepository:
self
.repository];
}
- (GTReference *)
resolvedReference
{
GTReference *resolvedReference = [
self
.class
referenceByResolvingSymbolicReference:
self
error:
NULL
];
return
resolvedReference ? resolvedReference : self;
}
- (
GTOID
*)
targetOID
{
return
[
self
.resolvedTarget
OID
];
}
- (GTReference *)
referenceByUpdatingTarget
:
(
NSString
*)
newTarget
message
:
(
NSString
*)
message
error
:
(
NSError
**)
error
{
NSParameterAssert
(newTarget !=
nil
);
int
gitError;
git_reference *newRef =
NULL
;
if
(
git_reference_type
(self.
git_reference
) ==
GIT_REFERENCE_DIRECT
) {
GTOID
*oid = [[
GTOID
alloc
]
initWithSHA:
newTarget
error:
error];
if
(oid ==
nil
)
return
nil
;
gitError =
git_reference_set_target
(&newRef, self.
git_reference
, oid.
git_oid
, message.
UTF8String
);
}
else
{
gitError =
git_reference_symbolic_set_target
(&newRef, self.
git_reference
, newTarget.
UTF8String
, message.
UTF8String
);
}
if
(gitError !=
GIT_OK
) {
if
(error !=
NULL
) *error = [
NSError
git_errorFor:
gitError
description:
@"
Failed to update reference
%@
to target
%@
.
"
,
self
.name, newTarget];
return
nil
;
}
return
[[
self
.class
alloc
]
initWithGitReference:
newRef
repository:
self
.repository];
}
- (
BOOL
)
deleteWithError
:
(
NSError
**)
error
{
int
gitError =
git_reference_delete
(self.
git_reference
);
if
(gitError !=
GIT_OK
) {
if
(error !=
NULL
) *error = [
NSError
git_errorFor:
gitError
description:
@"
Failed to delete reference
%@
.
"
,
self
.name];
return
NO
;
}
return
YES
;
}
- (GTReference *)
resolvedReferenceWithError
:
(
NSError
**)
error
{
return
[GTReference
referenceByResolvingSymbolicReference:
self
error:
error];
}
- (
const
git_oid *)
git_oid
{
return
git_reference_target
(self.
git_reference
);
}
- (
GTOID
*)
OID
{
const
git_oid *oid = self.
git_oid
;
if
(oid ==
NULL
)
return
nil
;
return
[[
GTOID
alloc
]
initWithGitOid:
oid];
}
- (GTReference *)
reloadedReferenceWithError
:
(
NSError
**)
error
{
return
[
self
.repository
lookUpReferenceWithName:
self
.name
error:
error];
}
+ (
NSError
*)
invalidReferenceError
{
return
[
NSError
git_errorFor:
GTReferenceErrorCodeInvalidReference
description:
@"
Invalid git_reference.
"
];
}
- (GTReflog *)
reflog
{
return
[[GTReflog
alloc
]
initWithReference:
self
];
}
+ (
BOOL
)
isValidReferenceName
:
(
NSString
*)
refName
{
return
git_reference_is_valid_name
(refName.
UTF8String
) ==
1
;
}
#
pragma mark
NSObject
- (
NSString
*)
description
{
return
[
NSString
stringWithFormat:
@"
<
%@
:
%p
>{ OID:
%@
, type:
%@
, remote:
%i
}
"
,
self
.class,
self
,
self
.
OID
,
referenceTypeToString
(
self
.referenceType), (
int
)
self
.remote];
}
- (
NSUInteger
)
hash
{
return
self.
name
.
hash
;
}
- (
BOOL
)
isEqual
:
(GTReference *)
reference
{
if
(self == reference)
return
YES
;
if
(![reference
isKindOfClass:
GTReference.class])
return
NO
;
return
[
self
.name
isEqual:
reference.name] && [
self
.unresolvedTarget
isEqual:
reference.unresolvedTarget];
}
@end
You can’t perform that action at this time.