Skip to content

Commit be373b0

Browse files
committed
Adding code to support SVN fetch,rebase,dcommit buttons and sensing of svn-remote configuration in repository. No implementation of git svn commands yet, just code for the buttons.
1 parent d2c7cfc commit be373b0

6 files changed

+115
-0
lines changed

PBGitConfig.h

+4
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@
1616

1717
- init;
1818
- initWithRepositoryPath:(NSString *)path;
19+
20+
// get config data: `git config -l`
21+
- (NSDictionary*) listConfigValuesInDir:(NSString*)inDir;
22+
1923
@end

PBGitConfig.m

+33
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,37 @@ - (void) setValue:(id)value forKeyPath:(NSString *)path
8888
// It doesn't exist at all. Write it locally.
8989
[self writeValue:value forKey:path global:NO];
9090
}
91+
92+
/**
93+
runs `git config -l` returning a dict of key-value pairs from the result
94+
95+
passing nil as directory passes '--global' flag
96+
*/
97+
- (NSDictionary*) listConfigValuesInDir:(NSString*)inDir
98+
{
99+
NSArray* arguments;
100+
101+
if (inDir == nil) {
102+
arguments = [NSArray arrayWithObjects:@"config", @"--global", @"-l", nil];
103+
} else {
104+
arguments = [NSArray arrayWithObjects:@"config", @"-l", nil];
105+
}
106+
107+
int ret = 1;
108+
NSString* output = [PBEasyPipe outputForCommand:[PBGitBinary path] withArgs:arguments inDir:inDir retValue:&ret];
109+
NSMutableDictionary *result = [NSMutableDictionary dictionary];
110+
if (ret==0) {
111+
NSArray *lines = [output componentsSeparatedByString:@"\n"];
112+
113+
for (NSString* line in lines) {
114+
NSRange equalsPos = [line rangeOfString:@"="];
115+
NSString* key = [line substringToIndex:equalsPos.location];
116+
NSString* value = [line substringFromIndex:equalsPos.location+1];
117+
[result setObject:value forKey:key];
118+
}
119+
}
120+
121+
return [NSDictionary dictionaryWithDictionary:result];
122+
}
123+
91124
@end

PBGitRepository.h

+5
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ static NSString * PBStringFromBranchFilterType(PBGitXBranchFilterType type) {
6969
- (BOOL) deleteRemote:(PBGitRef *)ref;
7070
- (BOOL) deleteRef:(PBGitRef *)ref;
7171

72+
- (BOOL) hasSvnRemote;
73+
- (BOOL) svnFetch:(NSString*)remoteName;
74+
- (BOOL) svnRebase:(NSString*)remoteName;
75+
- (BOOL) svnDcommit:(NSString*)commitURL;
76+
7277
- (NSFileHandle*) handleForCommand:(NSString*) cmd;
7378
- (NSFileHandle*) handleForArguments:(NSArray*) args;
7479
- (NSFileHandle *) handleInWorkDirForArguments:(NSArray *)args;

PBGitRepository.m

+44
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,50 @@ - (BOOL) deleteRef:(PBGitRef *)ref
885885
return YES;
886886
}
887887

888+
#pragma mark git svn commands
889+
890+
/**
891+
determines if the current repository has a git-svn configured remote
892+
*/
893+
- (BOOL) hasSvnRemote
894+
{
895+
NSDictionary* configValues = [config listConfigValuesInDir:[self workingDirectory]];
896+
897+
for (NSString* key in configValues) {
898+
if ([key hasPrefix:@"svn-remote."]) return YES;
899+
}
900+
return NO;
901+
}
902+
903+
/**
904+
call `git svn fetch` with an optional remote name
905+
906+
remoteName can be NULL
907+
*/
908+
- (BOOL) svnFetch:(NSString*)remoteName
909+
{
910+
return YES;
911+
}
912+
913+
/**
914+
call `git svn rebase` with an optional remote name
915+
916+
remoteName can be NULL
917+
*/
918+
- (BOOL) svnRebase:(NSString*)remoteName
919+
{
920+
return YES;
921+
}
922+
923+
/**
924+
call `git svn dcommit` with optional commitURL
925+
926+
commitURL can be NULL
927+
*/
928+
- (BOOL) svnDcommit:(NSString*)commitURL
929+
{
930+
return YES;
931+
}
888932

889933
#pragma mark GitX Scripting
890934

PBGitSidebarController.h

+7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
IBOutlet NSPopUpButton *actionButton;
2121
IBOutlet NSSegmentedControl *remoteControls;
2222

23+
IBOutlet NSButton* svnFetchButton;
24+
IBOutlet NSButton* svnRebaseButton;
25+
IBOutlet NSButton* svnDcommitButton;
26+
2327
NSMutableArray *items;
2428

2529
/* Specific things */
@@ -37,6 +41,9 @@
3741
- (NSMenu *) menuForRow:(NSInteger)row;
3842

3943
- (IBAction) fetchPullPushAction:(id)sender;
44+
- (IBAction) svnFetch:(id)sender;
45+
- (IBAction) svnRebase:(id)sender;
46+
- (IBAction) svnDcommit:(id)sender;
4047

4148
- (void)setHistorySearch:(NSString *)searchString mode:(NSInteger)mode;
4249

PBGitSidebarController.m

+22
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,12 @@ - (void) updateRemoteControls
371371
[remoteControls setEnabled:hasRemote forSegment:kFetchSegment];
372372
[remoteControls setEnabled:hasRemote forSegment:kPullSegment];
373373
[remoteControls setEnabled:hasRemote forSegment:kPushSegment];
374+
375+
// get config
376+
BOOL hasSVN = [repository hasSvnRemote];
377+
[svnFetchButton setEnabled:hasSVN];
378+
[svnRebaseButton setEnabled:hasSVN];
379+
[svnDcommitButton setEnabled:hasSVN];
374380
}
375381

376382
- (IBAction) fetchPullPushAction:(id)sender
@@ -408,5 +414,21 @@ - (IBAction) fetchPullPushAction:(id)sender
408414
}
409415
}
410416

417+
- (IBAction) svnFetch:(id)sender
418+
{
419+
[repository svnFetch:nil];
420+
}
421+
422+
- (IBAction) svnRebase:(id)sender
423+
{
424+
printf("git svn rebase");
425+
[repository svnRebase:nil];
426+
}
427+
428+
- (IBAction) svnDcommit:(id)sender
429+
{
430+
printf("git svn dcommit");
431+
[repository svnDcommit:nil];
432+
}
411433

412434
@end

0 commit comments

Comments
 (0)