@@ -28,6 +28,14 @@ void usage(char const *programName)
28
28
printf (" -v, --version prints version info for both GitX and git\n " );
29
29
printf (" --git-path prints the path to the directory containing git\n " );
30
30
printf (" \n " );
31
+ printf (" Repository path\n " );
32
+ printf (" By default gitx opens the repository in the current directory.\n " );
33
+ printf (" Use --git-dir= to send commands to a repository somewhere else.\n " );
34
+ printf (" Note: This must be the first argument.\n " );
35
+ printf (" \n " );
36
+ printf (" --git-dir=<path> [gitx commands]\n " );
37
+ printf (" send the gitx commands to the repository located at <path>\n " );
38
+ printf (" \n " );
31
39
printf (" Commit/Stage view\n " );
32
40
printf (" -c, --commit start GitX in commit/stage mode\n " );
33
41
printf (" \n " );
@@ -153,9 +161,32 @@ void handleOpenRepository(NSURL *repositoryURL, NSMutableArray *arguments)
153
161
#pragma mark -
154
162
#pragma mark main
155
163
156
- NSURL *workingDirectoryURL ()
164
+
165
+ #define kGitDirPrefix @" --git-dir="
166
+
167
+ NSURL *workingDirectoryURL (NSMutableArray *arguments)
157
168
{
158
- NSString *path = [[[NSProcessInfo processInfo ] environment ] objectForKey: @" PWD" ];
169
+ NSString *path = nil ;
170
+
171
+ if ([arguments count ] && [[arguments objectAtIndex: 0 ] hasPrefix: kGitDirPrefix ]) {
172
+ path = [[[arguments objectAtIndex: 0 ] substringFromIndex: [kGitDirPrefix length ]] stringByStandardizingPath ];
173
+
174
+ // the path must exist and point to a directory
175
+ BOOL isDirectory = YES ;
176
+ if (![[NSFileManager defaultManager ] fileExistsAtPath: path isDirectory: &isDirectory] || !isDirectory) {
177
+ if (!isDirectory)
178
+ printf (" Fatal: --git-dir path does not point to a directory.\n " );
179
+ else
180
+ printf (" Fatal: --git-dir path does not exist.\n " );
181
+ printf (" Cannot open git repository at path: '%s '\n " , [path UTF8String ]);
182
+ exit (2 );
183
+ }
184
+
185
+ // remove the git-dir argument
186
+ [arguments removeObjectAtIndex: 0 ];
187
+ } else {
188
+ path = [[[NSProcessInfo processInfo ] environment ] objectForKey: @" PWD" ];
189
+ }
159
190
160
191
NSURL *url = [NSURL fileURLWithPath: path isDirectory: YES ];
161
192
if (!url) {
@@ -195,7 +226,7 @@ int main(int argc, const char** argv)
195
226
196
227
// From this point, we require a working directory and the arguments
197
228
NSMutableArray *arguments = argumentsArray ();
198
- NSURL *wdURL = workingDirectoryURL ();
229
+ NSURL *wdURL = workingDirectoryURL (arguments );
199
230
200
231
if ([arguments count ] > 0 && ([[arguments objectAtIndex: 0 ] isEqualToString: @" --diff" ] ||
201
232
[[arguments objectAtIndex: 0 ] isEqualToString: @" -d" ])) {
0 commit comments