-
Notifications
You must be signed in to change notification settings - Fork 283
Expand file tree
/
Copy pathGTSubmodule.h
More file actions
170 lines (138 loc) · 6.37 KB
/
GTSubmodule.h
File metadata and controls
170 lines (138 loc) · 6.37 KB
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
//
// GTSubmodule.h
// ObjectiveGitFramework
//
// Created by Justin Spahr-Summers on 2013-05-29.
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "GTObject.h"
#import <git2/buffer.h>
#import <git2/submodule.h>
@class GTOID;
/// Determines which kinds of changes within the submodule repository will be
/// ignored when retrieving its status.
///
/// These flags are mutually exclusive.
typedef NS_ENUM(NSInteger, GTSubmoduleIgnoreRule) {
GTSubmoduleIgnoreUnspecified = GIT_SUBMODULE_IGNORE_UNSPECIFIED,
GTSubmoduleIgnoreNone = GIT_SUBMODULE_IGNORE_NONE,
GTSubmoduleIgnoreUntracked = GIT_SUBMODULE_IGNORE_UNTRACKED,
GTSubmoduleIgnoreDirty = GIT_SUBMODULE_IGNORE_DIRTY,
GTSubmoduleIgnoreAll = GIT_SUBMODULE_IGNORE_ALL
};
/// Describes the status of a submodule.
///
/// These flags may be ORed together.
typedef NS_OPTIONS(NSInteger, GTSubmoduleStatus) {
GTSubmoduleStatusUnknown = 0,
GTSubmoduleStatusExistsInHEAD = GIT_SUBMODULE_STATUS_IN_HEAD,
GTSubmoduleStatusExistsInIndex = GIT_SUBMODULE_STATUS_IN_INDEX,
GTSubmoduleStatusExistsInConfig = GIT_SUBMODULE_STATUS_IN_CONFIG,
GTSubmoduleStatusExistsInWorkingDirectory = GIT_SUBMODULE_STATUS_IN_WD,
GTSubmoduleStatusAddedToIndex = GIT_SUBMODULE_STATUS_INDEX_ADDED,
GTSubmoduleStatusDeletedFromIndex = GIT_SUBMODULE_STATUS_INDEX_DELETED,
GTSubmoduleStatusModifiedInIndex = GIT_SUBMODULE_STATUS_INDEX_MODIFIED,
GTSubmoduleStatusUninitialized = GIT_SUBMODULE_STATUS_WD_UNINITIALIZED,
GTSubmoduleStatusAddedToWorkingDirectory = GIT_SUBMODULE_STATUS_WD_ADDED,
GTSubmoduleStatusDeletedFromWorkingDirectory = GIT_SUBMODULE_STATUS_WD_DELETED,
GTSubmoduleStatusModifiedInWorkingDirectory = GIT_SUBMODULE_STATUS_WD_MODIFIED,
GTSubmoduleStatusDirtyIndex = GIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED,
GTSubmoduleStatusDirtyWorkingDirectory = GIT_SUBMODULE_STATUS_WD_WD_MODIFIED,
GTSubmoduleStatusUntrackedFilesInWorkingDirectory = GIT_SUBMODULE_STATUS_WD_UNTRACKED
};
NS_ASSUME_NONNULL_BEGIN
/// Represents a submodule within its parent repository.
@interface GTSubmodule : NSObject
/// The repository that this submodule lives within.
@property (nonatomic, strong, readonly) GTRepository *parentRepository;
/// The current ignore rule for this submodule.
@property (nonatomic, readonly, assign) GTSubmoduleIgnoreRule ignoreRule;
/// The OID that the submodule is pinned to in the parent repository's index.
///
/// If the submodule is not in the index, this will be nil.
@property (nonatomic, strong, readonly, nullable) GTOID *indexOID;
/// The OID that the submodule is pinned to in the parent repository's HEAD
/// commit.
///
/// If the submodule is not in HEAD, this will be nil.
@property (nonatomic, strong, readonly, nullable) GTOID *HEADOID;
/// The OID that is checked out in the submodule repository.
///
/// If the submodule is not checked out, this will be nil.
@property (nonatomic, strong, readonly, nullable) GTOID *workingDirectoryOID;
/// The name of this submodule.
@property (nonatomic, copy, readonly, nullable) NSString *name;
/// The path to this submodule, relative to its parent repository's root.
@property (nonatomic, copy, readonly, nullable) NSString *path;
/// The remote URL provided for this submodule, read from the parent repository's
/// `.git/config` or `.gitmodules` file.
@property (nonatomic, copy, readonly, nullable) NSString *URLString;
- (instancetype)init NS_UNAVAILABLE;
/// Initializes the receiver to wrap the given submodule object. Designated initializer.
///
/// submodule - The submodule to wrap. The receiver will not own this object, so
/// it must not be freed while the GTSubmodule is alive. This must
/// not be NULL.
/// repository - The repository that contains the submodule. This must not be
/// nil.
///
/// Returns an initialized GTSubmodule, or nil if an error occurs.
- (nullable instancetype)initWithGitSubmodule:(git_submodule *)submodule parentRepository:(GTRepository *)repository NS_DESIGNATED_INITIALIZER;
/// The underlying `git_submodule` object.
- (git_submodule *)git_submodule __attribute__((objc_returns_inner_pointer));
/// Reloads the receiver's configuration from the parent repository.
///
/// This will mutate properties on the receiver.
///
/// Returns whether reloading succeeded.
- (BOOL)reload:(NSError **)error;
/// Write a new ignore rule to disk and get the resulting submodule. The
/// receiver will not have the new ignore rule. To update the receiver, call
/// `-reload:`.
///
/// ignoreRule - The ignore rule.
/// error - The error if one occurred.
///
/// Returns the updated submodule or nil if an error occurred.
- (nullable GTSubmodule *)submoduleByUpdatingIgnoreRule:(GTSubmoduleIgnoreRule)ignoreRule error:(NSError **)error;
/// Synchronizes the submodule repository's configuration files with the settings
/// from the parent repository.
///
/// Returns whether the synchronization succeeded.
- (BOOL)sync:(NSError **)error;
/// Opens the submodule repository.
///
/// If the submodule is not currently checked out, this will fail.
///
/// Returns the opened repository, or nil if an error occurs.
- (nullable GTRepository *)submoduleRepository:(NSError **)error;
/// Calls `-statusWithIgnoreRule:error:` with the submodule's ignore rule.
- (GTSubmoduleStatus)status:(NSError **)error;
/// Determine the status for the submodule using the given ignore rule.
///
/// ignoreRule - The ignore rule to use in calculating status.
/// error - The error if one occurred.
///
/// Returns the status or `GTSubmoduleStatusUnknown` if an error occurred.
- (GTSubmoduleStatus)statusWithIgnoreRule:(GTSubmoduleIgnoreRule)ignoreRule error:(NSError **)error;
/// Initializes the submodule by copying its information into the parent
/// repository's `.git/config` file. This is equivalent to `git submodule init`
/// on the command line.
///
/// overwrite - Whether to force an update to the `.git/config` file. If NO,
/// existing entries will not be overwritten.
/// error - If not NULL, set to any error that occurs.
///
/// Returns whether the initialization succeeded.
- (BOOL)writeToParentConfigurationDestructively:(BOOL)overwrite error:(NSError **)error;
/// Add the current HEAD to the parent repository's index.
///
/// Note that it does *not* write the index.
///
/// error - The error if one occurred.
///
/// Returns whether the add was successful.
- (BOOL)addToIndex:(NSError **)error;
@end
NS_ASSUME_NONNULL_END