@@ -23,6 +23,8 @@ void usage(char const *programName)
23
23
printf (" or: %s (--all|--local|--branch) [branch/tag]\n " , programName);
24
24
printf (" or: %s <revlist options>\n " , programName);
25
25
printf (" or: %s (--diff)\n " , programName);
26
+ printf (" or: %s (--init)\n " , programName);
27
+ printf (" or: %s (--clone <repository> [destination])\n " , programName);
26
28
printf (" \n " );
27
29
printf (" -h, --help print this help\n " );
28
30
printf (" -v, --version prints version info for both GitX and git\n " );
@@ -60,6 +62,15 @@ void usage(char const *programName)
60
62
printf (" shows the diff in a window in GitX\n " );
61
63
printf (" git diff [options] | gitx\n " );
62
64
printf (" use gitx to pipe diff output to a GitX window\n " );
65
+ printf (" \n " );
66
+ printf (" Creating repositories\n " );
67
+ printf (" These commands will create a git repository and then open it up in GitX\n " );
68
+ printf (" \n " );
69
+ printf (" --init creates (or reinitializes) a git repository\n " );
70
+ printf (" --clone <repository URL> [destination path]\n " );
71
+ printf (" clones the repository (at the specified URL) into the current\n " );
72
+ printf (" directory or into the specified path\n " );
73
+ printf (" \n " );
63
74
exit (1 );
64
75
}
65
76
@@ -157,6 +168,37 @@ void handleOpenRepository(NSURL *repositoryURL, NSMutableArray *arguments)
157
168
}
158
169
}
159
170
171
+ void handleInit (NSURL *repositoryURL)
172
+ {
173
+ GitXApplication *gitXApp = [SBApplication applicationWithBundleIdentifier: kGitXBundleIdentifier ];
174
+ [gitXApp initRepository: repositoryURL];
175
+
176
+ exit (0 );
177
+ }
178
+
179
+ void handleClone (NSURL *repositoryURL, NSMutableArray *arguments)
180
+ {
181
+ if ([arguments count ]) {
182
+ NSString *repository = [arguments objectAtIndex: 0 ];
183
+
184
+ if ([arguments count ] > 1 ) {
185
+ NSURL *url = [NSURL fileURLWithPath: [arguments objectAtIndex: 1 ]];
186
+ if (url)
187
+ repositoryURL = url;
188
+ }
189
+
190
+ GitXApplication *gitXApp = [SBApplication applicationWithBundleIdentifier: kGitXBundleIdentifier ];
191
+ [gitXApp cloneRepository: repository to: repositoryURL isBare: NO ];
192
+ }
193
+ else {
194
+ printf (" Error: --clone needs the URL of the repository to clone.\n " );
195
+ exit (2 );
196
+ }
197
+
198
+
199
+ exit (0 );
200
+ }
201
+
160
202
161
203
#pragma mark -
162
204
#pragma mark main
@@ -228,10 +270,23 @@ int main(int argc, const char** argv)
228
270
NSMutableArray *arguments = argumentsArray ();
229
271
NSURL *wdURL = workingDirectoryURL (arguments);
230
272
231
- if ([arguments count ] > 0 && ([[arguments objectAtIndex: 0 ] isEqualToString: @" --diff" ] ||
232
- [[arguments objectAtIndex: 0 ] isEqualToString: @" -d" ])) {
233
- [arguments removeObjectAtIndex: 0 ];
234
- handleDiffWithArguments (wdURL, arguments);
273
+ if ([arguments count ]) {
274
+ NSString *firstArgument = [arguments objectAtIndex: 0 ];
275
+
276
+ if ([firstArgument isEqualToString: @" --diff" ] || [firstArgument isEqualToString: @" -d" ]) {
277
+ [arguments removeObjectAtIndex: 0 ];
278
+ handleDiffWithArguments (wdURL, arguments);
279
+ }
280
+
281
+ if ([firstArgument isEqualToString: @" --init" ]) {
282
+ [arguments removeObjectAtIndex: 0 ];
283
+ handleInit (wdURL);
284
+ }
285
+
286
+ if ([firstArgument isEqualToString: @" --clone" ]) {
287
+ [arguments removeObjectAtIndex: 0 ];
288
+ handleClone (wdURL, arguments);
289
+ }
235
290
}
236
291
237
292
// No commands handled by gitx, open the current dir in GitX with the arguments
0 commit comments