Skip to content

Commit f4a6d3f

Browse files
committed
Set the working directory for arguments sent from the cli
This allows running the gitx cli in a subdirectory and specifying file paths in that directory without having to type out the full path.
1 parent 8591eff commit f4a6d3f

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

PBGitRepository.m

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ - (BOOL) deleteRef:(PBGitRef *)ref
905905

906906
#pragma mark GitX Scripting
907907

908-
- (void)handleRevListArguments:(NSArray *)arguments
908+
- (void)handleRevListArguments:(NSArray *)arguments inWorkingDirectory:(NSURL *)workingDirectory
909909
{
910910
if (![arguments count])
911911
return;
@@ -915,19 +915,23 @@ - (void)handleRevListArguments:(NSArray *)arguments
915915
// the argument may be a branch or tag name but will probably not be the full reference
916916
if ([arguments count] == 1) {
917917
PBGitRef *refArgument = [self refForName:[arguments lastObject]];
918-
if (refArgument)
918+
if (refArgument) {
919919
revListSpecifier = [[PBGitRevSpecifier alloc] initWithRef:refArgument];
920+
revListSpecifier.workingDirectory = workingDirectory;
921+
}
920922
}
921923

922-
if (!revListSpecifier)
924+
if (!revListSpecifier) {
923925
revListSpecifier = [[PBGitRevSpecifier alloc] initWithParameters:arguments];
926+
revListSpecifier.workingDirectory = workingDirectory;
927+
}
924928

925929
self.currentBranch = [self addBranch:revListSpecifier];
926930
[PBGitDefaults setShowStageView:NO];
927931
[self.windowController showHistoryView:self];
928932
}
929933

930-
- (void)handleBranchFilterEventForFilter:(PBGitXBranchFilterType)filter additionalArguments:(NSMutableArray *)arguments
934+
- (void)handleBranchFilterEventForFilter:(PBGitXBranchFilterType)filter additionalArguments:(NSMutableArray *)arguments inWorkingDirectory:(NSURL *)workingDirectory
931935
{
932936
self.currentBranchFilter = filter;
933937
[PBGitDefaults setShowStageView:NO];
@@ -936,11 +940,11 @@ - (void)handleBranchFilterEventForFilter:(PBGitXBranchFilterType)filter addition
936940
// treat any additional arguments as a rev-list specifier
937941
if ([arguments count] > 1) {
938942
[arguments removeObjectAtIndex:0];
939-
[self handleRevListArguments:arguments];
943+
[self handleRevListArguments:arguments inWorkingDirectory:workingDirectory];
940944
}
941945
}
942946

943-
- (void)handleGitXScriptingArguments:(NSAppleEventDescriptor *)argumentsList
947+
- (void)handleGitXScriptingArguments:(NSAppleEventDescriptor *)argumentsList inWorkingDirectory:(NSURL *)workingDirectory
944948
{
945949
NSMutableArray *arguments = [NSMutableArray array];
946950
uint argumentsIndex = 1; // AppleEvent list descriptor's are one based
@@ -964,22 +968,22 @@ - (void)handleGitXScriptingArguments:(NSAppleEventDescriptor *)argumentsList
964968
}
965969

966970
if ([firstArgument isEqualToString:@"--all"]) {
967-
[self handleBranchFilterEventForFilter:kGitXAllBranchesFilter additionalArguments:arguments];
971+
[self handleBranchFilterEventForFilter:kGitXAllBranchesFilter additionalArguments:arguments inWorkingDirectory:workingDirectory];
968972
return;
969973
}
970974

971975
if ([firstArgument isEqualToString:@"--local"]) {
972-
[self handleBranchFilterEventForFilter:kGitXLocalRemoteBranchesFilter additionalArguments:arguments];
976+
[self handleBranchFilterEventForFilter:kGitXLocalRemoteBranchesFilter additionalArguments:arguments inWorkingDirectory:workingDirectory];
973977
return;
974978
}
975979

976980
if ([firstArgument isEqualToString:@"--branch"]) {
977-
[self handleBranchFilterEventForFilter:kGitXSelectedBranchFilter additionalArguments:arguments];
981+
[self handleBranchFilterEventForFilter:kGitXSelectedBranchFilter additionalArguments:arguments inWorkingDirectory:workingDirectory];
978982
return;
979983
}
980984

981985
// if the argument is not a known command then treat it as a rev-list specifier
982-
[self handleRevListArguments:arguments];
986+
[self handleRevListArguments:arguments inWorkingDirectory:workingDirectory];
983987
}
984988

985989
// see if the current appleEvent has the command line arguments from the gitx cli
@@ -996,9 +1000,10 @@ - (void)showWindows
9961000
// on app launch there may be many repositories opening, so double check that this is the right repo
9971001
NSString *path = [[eventRecord paramDescriptorForKeyword:typeFileURL] stringValue];
9981002
if (path) {
999-
if ([[PBGitRepository gitDirForURL:[NSURL URLWithString:path]] isEqual:[self fileURL]]) {
1003+
NSURL *workingDirectory = [NSURL URLWithString:path];
1004+
if ([[PBGitRepository gitDirForURL:workingDirectory] isEqual:[self fileURL]]) {
10001005
NSAppleEventDescriptor *argumentsList = [eventRecord paramDescriptorForKeyword:kGitXAEKeyArgumentsList];
1001-
[self handleGitXScriptingArguments:argumentsList];
1006+
[self handleGitXScriptingArguments:argumentsList inWorkingDirectory:workingDirectory];
10021007

10031008
// showWindows may be called more than once during app launch so remove the CLI data after we handle the event
10041009
[currentAppleEvent removeDescriptorWithKeyword:keyAEPropData];

0 commit comments

Comments
 (0)