Skip to content

Commit d5049ab

Browse files
committed
Merge branch 'master' into new_nullable_annotation
2 parents f9058bc + 4673546 commit d5049ab

35 files changed

+263
-101
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
osx_image: xcode7
1+
osx_image: xcode8
22
language: objective-c
33
matrix:
44
fast_finish: true
55
include:
6-
- osx_image: xcode7.3
6+
- osx_image: xcode8
77
env:
88
- SCHEME="ObjectiveGit Mac"
9-
- osx_image: xcode7.3
9+
- osx_image: xcode8
1010
env:
1111
- SCHEME="ObjectiveGit iOS"
1212
before_install:

Cartfile.resolved

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
github "Quick/Nimble" "v4.0.0"
2-
github "Quick/Quick" "v0.9.2"
3-
github "ZipArchive/ZipArchive" "v1.1"
1+
github "Quick/Nimble" "v4.1.0"
2+
github "Quick/Quick" "v0.9.3"
3+
github "ZipArchive/ZipArchive" "v1.6.2"
44
github "jspahrsummers/xcconfigs" "0.9"

Carthage/Checkouts/ZipArchive

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License
22

3-
Copyright (c) 2012 libgit2 contributors
3+
Copyright (c) 2016 libgit2 contributors
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

ObjectiveGit/Categories/NSError+Git.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@
2929

3030
#import <Foundation/Foundation.h>
3131

32+
/// The error domain used by Objective-Git
3233
extern NSString * const GTGitErrorDomain;
3334

35+
/// Error userinfo keys
36+
extern NSString * const GTGitErrorOID;
37+
3438
@interface NSError (Git)
3539

3640
/// Describes the given libgit2 error code, using any message provided by

ObjectiveGit/Categories/NSError+Git.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#import "git2/errors.h"
3232

3333
NSString * const GTGitErrorDomain = @"GTGitErrorDomain";
34+
NSString * const GTGitErrorOID = @"GTOID";
3435

3536
@implementation NSError (Git)
3637

ObjectiveGit/GTDiff.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ typedef NS_OPTIONS(NSInteger, GTDiffFindOptionsFlags) {
308308
- (git_diff *)git_diff __attribute__((objc_returns_inner_pointer));
309309

310310
/// The number of deltas of the given type that are contained in the diff.
311-
- (NSUInteger)numberOfDeltasWithType:(GTDiffDeltaType)deltaType;
311+
- (NSUInteger)numberOfDeltasWithType:(GTDeltaType)deltaType;
312312

313313
/// Enumerate the deltas in a diff.
314314
///

ObjectiveGit/GTDiff.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ - (NSUInteger)deltaCount {
234234
return git_diff_num_deltas(self.git_diff);
235235
}
236236

237-
- (NSUInteger)numberOfDeltasWithType:(GTDiffDeltaType)deltaType {
237+
- (NSUInteger)numberOfDeltasWithType:(GTDeltaType)deltaType {
238238
return git_diff_num_deltas_of_type(self.git_diff, (git_delta_t)deltaType);
239239
}
240240

ObjectiveGit/GTDiffDelta.h

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,38 @@
1717

1818
/// The type of change that this delta represents.
1919
///
20-
/// GTDiffFileDeltaUnmodified - No Change.
21-
/// GTDiffFileDeltaAdded - The file was added to the index.
22-
/// GTDiffFileDeltaDeleted - The file was removed from the working directory.
23-
/// GTDiffFileDeltaModified - The file was modified.
24-
/// GTDiffFileDeltaRenamed - The file has been renamed.
25-
/// GTDiffFileDeltaCopied - The file was duplicated.
26-
/// GTDiffFileDeltaIgnored - The file was ignored by git.
27-
/// GTDiffFileDeltaUntracked - The file has been added to the working directory
20+
/// GTDeltaTypeUnmodified - No Change.
21+
/// GTDeltaTypeAdded - The file was added to the index.
22+
/// GTDeltaTypeDeleted - The file was removed from the working directory.
23+
/// GTDeltaTypeModified - The file was modified.
24+
/// GTDeltaTypeRenamed - The file has been renamed.
25+
/// GTDeltaTypeCopied - The file was duplicated.
26+
/// GTDeltaTypeIgnored - The file was ignored by git.
27+
/// GTDeltaTypeUntracked - The file has been added to the working directory
2828
/// and is therefore currently untracked.
29-
/// GTDiffFileDeltaTypeChange - The file has changed from a blob to either a
29+
/// GTDeltaTypeTypeChange - The file has changed from a blob to either a
3030
/// submodule, symlink or directory. Or vice versa.
31-
typedef NS_ENUM(NSInteger, GTDiffDeltaType) {
32-
GTDiffFileDeltaUnmodified = GIT_DELTA_UNMODIFIED,
33-
GTDiffFileDeltaAdded = GIT_DELTA_ADDED,
34-
GTDiffFileDeltaDeleted = GIT_DELTA_DELETED,
35-
GTDiffFileDeltaModified = GIT_DELTA_MODIFIED,
36-
GTDiffFileDeltaRenamed = GIT_DELTA_RENAMED,
37-
GTDiffFileDeltaCopied = GIT_DELTA_COPIED,
38-
GTDiffFileDeltaIgnored = GIT_DELTA_IGNORED,
39-
GTDiffFileDeltaUntracked = GIT_DELTA_UNTRACKED,
40-
GTDiffFileDeltaTypeChange = GIT_DELTA_TYPECHANGE,
31+
/// GTDeltaTypeConflicted - The file is conflicted in the working directory.
32+
typedef NS_ENUM(NSInteger, GTDeltaType) {
33+
GTDeltaTypeUnmodified = GIT_DELTA_UNMODIFIED,
34+
GTDeltaTypeAdded = GIT_DELTA_ADDED,
35+
GTDeltaTypeDeleted = GIT_DELTA_DELETED,
36+
GTDeltaTypeModified = GIT_DELTA_MODIFIED,
37+
GTDeltaTypeRenamed = GIT_DELTA_RENAMED,
38+
GTDeltaTypeCopied = GIT_DELTA_COPIED,
39+
GTDeltaTypeIgnored = GIT_DELTA_IGNORED,
40+
GTDeltaTypeUntracked = GIT_DELTA_UNTRACKED,
41+
GTDeltaTypeTypeChange = GIT_DELTA_TYPECHANGE,
42+
GTDeltaTypeUnreadable = GIT_DELTA_UNREADABLE,
43+
GTDeltaTypeConflicted = GIT_DELTA_CONFLICTED,
4144
};
4245

4346
NS_ASSUME_NONNULL_BEGIN
4447

4548
/// A class representing a single change within a diff.
4649
///
4750
/// The change may not be simply a change of text within a given file, it could
48-
/// be that the file was renamed, or added to the index. See `GTDiffDeltaType`
51+
/// be that the file was renamed, or added to the index. See `GTDeltaType`
4952
/// for the types of change represented.
5053
@interface GTDiffDelta : NSObject
5154

@@ -68,7 +71,9 @@ NS_ASSUME_NONNULL_BEGIN
6871
/// The type of change that this delta represents.
6972
///
7073
/// Think "status" as in `git status`.
71-
@property (nonatomic, readonly) GTDiffDeltaType type;
74+
@property (nonatomic, readonly) GTDeltaType type;
75+
76+
@property (nonatomic, readonly, assign) double similarity;
7277

7378
/// Diffs the given blob and data buffer.
7479
///

ObjectiveGit/GTDiffDelta.m

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,12 @@ - (GTDiffFile *)newFile {
5656
return [[GTDiffFile alloc] initWithGitDiffFile:self.git_diff_delta.new_file];
5757
}
5858

59-
- (GTDiffDeltaType)type {
60-
return (GTDiffDeltaType)self.git_diff_delta.status;
59+
- (GTDeltaType)type {
60+
return (GTDeltaType)self.git_diff_delta.status;
61+
}
62+
63+
- (double)similarity {
64+
return (double)(self.git_diff_delta.similarity / 100.0);
6165
}
6266

6367
#pragma mark Lifecycle

ObjectiveGit/GTDiffHunk.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ NS_ASSUME_NONNULL_BEGIN
2222
/// The number of lines represented in the hunk.
2323
@property (nonatomic, readonly) NSUInteger lineCount;
2424

25+
/// The starting line number in the old file
26+
@property (nonatomic, readonly) NSUInteger oldStart;
27+
28+
/// The number of lines in the old file
29+
@property (nonatomic, readonly) NSUInteger oldLines;
30+
31+
/// The starting line number in the new file
32+
@property (nonatomic, readonly) NSUInteger newStart;
33+
34+
/// The number of lines in the new file
35+
@property (nonatomic, readonly) NSUInteger newLines;
36+
2537
- (instancetype)init NS_UNAVAILABLE;
2638

2739
/// Designated initialiser.

ObjectiveGit/GTDiffHunk.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ - (instancetype)initWithPatch:(GTDiffPatch *)patch hunkIndex:(NSUInteger)hunkInd
4040
int result = git_patch_get_hunk(&_git_hunk, &gitLineCount, patch.git_patch, hunkIndex);
4141
if (result != GIT_OK) return nil;
4242
_lineCount = gitLineCount;
43+
_oldStart = self.git_hunk->old_start;
44+
_oldLines = self.git_hunk->old_lines;
45+
_newStart = self.git_hunk->new_start;
46+
_newLines = self.git_hunk->new_lines;
4347

4448
_patch = patch;
4549
_hunkIndex = hunkIndex;

ObjectiveGit/GTEnumerator.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,16 @@ NS_ASSUME_NONNULL_BEGIN
117117
/// Returns a (possibly empty) array of GTCommits, or nil if an error occurs.
118118
- (NSArray<GTCommit *> * _Nullable)allObjectsWithError:(NSError **)error;
119119

120+
/// Get the next OID.
121+
///
122+
/// success - If not NULL, this will be set to whether getting the next object
123+
/// was successful. This will be YES if the receiver is exhausted, so
124+
/// it can be used to interpret the meaning of a nil return value.
125+
/// error - If not NULL, set to any error that occurs during traversal.
126+
///
127+
/// Returns nil if an error occurs or the enumeration is done.
128+
- (nullable GTOID *)nextOIDWithSuccess:(nullable BOOL *)success error:(NSError **)error;
129+
120130
/// Gets the next commit.
121131
///
122132
/// success - If not NULL, this will be set to whether getting the next object

ObjectiveGit/GTEnumerator.m

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,16 +145,34 @@ - (void)resetWithOptions:(GTEnumeratorOptions)options {
145145

146146
#pragma mark Enumerating
147147

148-
- (GTCommit *)nextObjectWithSuccess:(BOOL *)success error:(NSError **)error {
148+
- (GTOID *)nextOIDWithSuccess:(BOOL *)success error:(NSError **)error {
149149
git_oid oid;
150+
150151
int gitError = git_revwalk_next(&oid, self.walk);
151152
if (gitError == GIT_ITEROVER) {
152153
if (success != NULL) *success = YES;
153154
return nil;
154155
}
156+
if (gitError != GIT_OK) {
157+
if (success != NULL) *success = NO;
158+
if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Enumeration failed"];
159+
return nil;
160+
}
161+
162+
if (success != NULL) *success = YES;
163+
return [GTOID oidWithGitOid:&oid];
164+
}
165+
166+
- (GTCommit *)nextObjectWithSuccess:(BOOL *)success error:(NSError **)error {
167+
GTOID *oid = [self nextOIDWithSuccess:success error:error];
168+
if (oid == nil) {
169+
// We don't care whether the iteration completed, or an error occurred,
170+
// there's nothing to lookup.
171+
return nil;
172+
}
155173

156174
// Ignore error if we can't lookup object and just return nil.
157-
GTCommit *commit = [self.repository lookUpObjectByGitOid:&oid objectType:GTObjectTypeCommit error:error];
175+
GTCommit *commit = [self.repository lookUpObjectByOID:oid objectType:GTObjectTypeCommit error:error];
158176
if (success != NULL) *success = (commit != nil);
159177
return commit;
160178
}

ObjectiveGit/GTReflog+Private.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,8 @@
88

99
#import "GTReflog.h"
1010

11-
@class GTReference;
12-
1311
@interface GTReflog ()
1412

1513
- (instancetype _Nullable)init NS_UNAVAILABLE;
1614

17-
/// Initializes the receiver with a reference. Designated initializer.
18-
///
19-
/// reference - The reference whose reflog is being represented. Cannot be nil.
20-
///
21-
/// Returns the initialized object.
22-
- (instancetype _Nullable)initWithReference:(GTReference * _Nonnull)reference NS_DESIGNATED_INITIALIZER;
23-
2415
@end

ObjectiveGit/GTReflog.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#import <Foundation/Foundation.h>
1010

1111
@class GTSignature;
12+
@class GTReference;
1213
@class GTReflogEntry;
1314

1415
NS_ASSUME_NONNULL_BEGIN
@@ -20,6 +21,13 @@ NS_ASSUME_NONNULL_BEGIN
2021
/// The number of reflog entries.
2122
@property (nonatomic, readonly, assign) NSUInteger entryCount;
2223

24+
/// Initializes the receiver with a reference. Designated initializer.
25+
///
26+
/// reference - The reference whose reflog is being represented. Cannot be nil.
27+
///
28+
/// Returns the initialized object.
29+
- (nullable instancetype)initWithReference:(nonnull GTReference *)reference NS_DESIGNATED_INITIALIZER;
30+
2331
/// Writes a new entry to the reflog.
2432
///
2533
/// committer - The committer for the reflog entry. Cannot be nil.

ObjectiveGit/GTRemote.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,16 @@ typedef enum {
119119
/// if updating or saving the remote failed.
120120
- (BOOL)updateURLString:(NSString *)URLString error:(NSError **)error;
121121

122+
/// Updates the push URL string for this remote.
123+
///
124+
/// URLString - The URLString to update to. May not be nil.
125+
/// error - If not NULL, this will be set to any error that occurs when
126+
/// updating the URLString or saving the remote.
127+
///
128+
/// Returns YES if the push URLString was successfully updated, NO and an error
129+
/// if updating or saving the remote failed.
130+
- (BOOL)updatePushURLString:(NSString *)URLString error:(NSError **)error;
131+
122132
/// Adds a fetch refspec to this remote.
123133
///
124134
/// fetchRefspec - The fetch refspec string to add. May not be nil.

ObjectiveGit/GTRemote.m

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,21 @@ - (BOOL)updateURLString:(NSString *)URLString error:(NSError **)error {
204204
return YES;
205205
}
206206

207+
- (BOOL)updatePushURLString:(NSString *)URLString error:(NSError **)error {
208+
NSParameterAssert(URLString != nil);
209+
210+
if ([self.pushURLString isEqualToString:URLString]) return YES;
211+
212+
int gitError = git_remote_set_pushurl(self.repository.git_repository, self.name.UTF8String, URLString.UTF8String);
213+
if (gitError != GIT_OK) {
214+
if (error != NULL) {
215+
*error = [NSError git_errorFor:gitError description:@"Failed to update remote push URL string."];
216+
}
217+
return NO;
218+
}
219+
return YES;
220+
}
221+
207222
- (BOOL)addFetchRefspec:(NSString *)fetchRefspec error:(NSError **)error {
208223
NSParameterAssert(fetchRefspec != nil);
209224

ObjectiveGit/GTRepository+Status.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,23 +68,23 @@ - (BOOL)enumerateFileStatusWithOptions:(NSDictionary *)options error:(NSError **
6868
- (BOOL)isWorkingDirectoryClean {
6969
__block BOOL clean = YES;
7070
[self enumerateFileStatusWithOptions:nil error:NULL usingBlock:^(GTStatusDelta *headToIndex, GTStatusDelta *indexToWorkingDirectory, BOOL *stop) {
71-
GTStatusDeltaStatus headToIndexStatus = headToIndex.status;
72-
GTStatusDeltaStatus indexToWorkDirStatus = indexToWorkingDirectory.status;
71+
GTDeltaType headToIndexStatus = headToIndex.status;
72+
GTDeltaType indexToWorkDirStatus = indexToWorkingDirectory.status;
7373

7474
// first, have items been deleted?
75-
if (indexToWorkDirStatus == GTStatusDeltaStatusDeleted || headToIndexStatus == GTStatusDeltaStatusDeleted) {
75+
if (indexToWorkDirStatus == GTDeltaTypeDeleted || headToIndexStatus == GTDeltaTypeDeleted) {
7676
clean = NO;
7777
*stop = YES;
7878
}
7979

8080
// any untracked files?
81-
if (indexToWorkDirStatus == GTStatusDeltaStatusUntracked) {
81+
if (indexToWorkDirStatus == GTDeltaTypeUntracked) {
8282
clean = NO;
8383
*stop = YES;
8484
}
8585

8686
// next, have items been modified?
87-
if (indexToWorkDirStatus == GTStatusDeltaStatusModified || headToIndexStatus == GTStatusDeltaStatusModified) {
87+
if (indexToWorkDirStatus == GTDeltaTypeModified || headToIndexStatus == GTDeltaTypeModified) {
8888
clean = NO;
8989
*stop = YES;
9090
}

ObjectiveGit/GTRepository.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,16 @@ extern NSString * const GTRepositoryCloneOptionsCloneLocal;
110110
/// A NSURL pointing to a local file that contains PEM-encoded certificate chain.
111111
extern NSString *const GTRepositoryCloneOptionsServerCertificateURL;
112112

113+
/// Repository extended open control flags for
114+
/// +initWithURL:flags:ceilingDirs:error:.
115+
///
116+
/// See respository.h for documentation of each individual flag.
117+
typedef NS_OPTIONS(NSInteger, GTRepositoryOpenFlags) {
118+
GTRepositoryOpenNoSearch = GIT_REPOSITORY_OPEN_NO_SEARCH,
119+
GTRepositoryOpenCrossFS = GIT_REPOSITORY_OPEN_CROSS_FS,
120+
GTRepositoryOpenBare = GIT_REPOSITORY_OPEN_BARE,
121+
};
122+
113123
/// Initialization flags associated with `GTRepositoryInitOptionsFlags` for
114124
/// +initializeEmptyRepositoryAtFileURL:options:error:.
115125
///
@@ -209,6 +219,17 @@ typedef NS_ENUM(NSInteger, GTRepositoryStateType) {
209219
/// Returns the initialized repository, or nil if an error occurred.
210220
- (instancetype _Nullable)initWithURL:(NSURL *)localFileURL error:(NSError **)error;
211221

222+
/// Convenience initializer to find and open a repository with extended controls.
223+
///
224+
/// localFileURL - The file URL for the new repository. Cannot be nil.
225+
/// flags - A combination of the `GTRepositoryOpenFlags` flags.
226+
/// ceilingDirURLs - An array of URLs at which the search for a containing
227+
/// repository should terminate. Can be NULL.
228+
/// error - The error if one occurs.
229+
///
230+
/// Returns the initialized repository, or nil if an error occurred.
231+
- (nullable instancetype)initWithURL:(NSURL *)localFileURL flags:(NSInteger)flags ceilingDirs:(nullable NSArray<NSURL *> *)ceilingDirURLs error:(NSError **)error;
232+
212233
- (instancetype)init NS_UNAVAILABLE;
213234

214235
/// Initializes the receiver to wrap the given repository object. Designated initializer.

0 commit comments

Comments
 (0)