@@ -573,10 +573,14 @@ - (BOOL) checkRefFormat:(NSString *)refName
573
573
return YES ;
574
574
}
575
575
576
- - (BOOL ) refExists : (PBGitRef *)ref checkOnRemotesWithoutBranches : (BOOL )remoteCheck
576
+ - (BOOL )refExists : (PBGitRef *)ref checkOnRemotesWithoutBranches : (BOOL )remoteCheck resultMessage : ( NSString **) result
577
577
{
578
578
if (!ref)
579
579
{
580
+ if (result)
581
+ {
582
+ *result = @" Ref is Nil, can't progress check existence!" ;
583
+ }
580
584
return NO ;
581
585
}
582
586
@@ -607,44 +611,93 @@ - (BOOL) refExists:(PBGitRef *)ref checkOnRemotesWithoutBranches:(BOOL)remoteChe
607
611
arguments = [NSArray arrayWithObjects: @" for-each-ref" , [NSString stringWithFormat: @" %@%@ " ,kGitXBranchRefPrefix ,refShortName], nil ];
608
612
output = [self outputInWorkdirForArguments: arguments retValue: &retValue];
609
613
if (![output isEqualToString: @" " ])
614
+ {
615
+ if (result)
616
+ {
617
+ *result = [NSString stringWithFormat: @" %@ exists already local as branch!" ,refShortName];
618
+ }
610
619
return YES ;
620
+ }
611
621
612
622
// Check local refs/tags/ for ref
613
623
arguments = [NSArray arrayWithObjects: @" for-each-ref" , [NSString stringWithFormat: @" %@%@ " ,kGitXTagRefPrefix ,refShortName], nil ];
614
624
output = [self outputInWorkdirForArguments: arguments retValue: &retValue];
615
625
if (![output isEqualToString: @" " ])
626
+ {
627
+ if (result)
628
+ {
629
+ *result = [NSString stringWithFormat: @" %@ exists already local as tag!" ,refShortName];
630
+ }
616
631
return YES ;
632
+ }
617
633
618
634
// Check if any remote exists with refShortName
619
635
NSArray *repoRemotes = [self remotes ];
620
636
if ([repoRemotes containsObject: refShortName])
637
+ {
638
+ if (result)
639
+ {
640
+ *result = [NSString stringWithFormat: @" %@ exists already local as remotename!" ,refShortName];
641
+ }
621
642
return YES ;
622
-
623
- // Check Branches and Tags on any Remotes
643
+ }
644
+
645
+ NSMutableString *completeResults = [NSMutableString string ];
646
+
647
+ // Check Tags on any Remotes
624
648
if (repoRemotes && remoteCheck)
625
649
{
650
+
626
651
for (int i=0 ; i<[repoRemotes count ]; i++)
627
652
{
628
653
// Check Remote connection
629
- PBGitRef *remoteRef = [PBGitRef refFromString: [NSString stringWithFormat: @" %@%@ " ,kGitXRemoteRefPrefix ,[repoRemotes objectAtIndex: i]]];
630
- if ([self isRemoteConnected: remoteRef])
654
+ if ([self isRemoteConnected: [repoRemotes objectAtIndex: i]])
631
655
{
632
656
// Check remote refs/tags/ for ref
633
657
arguments = [NSArray arrayWithObjects: @" ls-remote" , @" -t" ,[repoRemotes objectAtIndex: i] ,refShortName, nil ];
634
658
output = [self outputInWorkdirForArguments: arguments retValue: &retValue];
635
659
if (![output isEqualToString: @" " ])
660
+ {
661
+ [completeResults appendFormat: @" %@ exists already as tag on remote %@ !" ,refShortName,[repoRemotes objectAtIndex: i]];
662
+ if (result)
663
+ {
664
+ *result = completeResults;
665
+ }
636
666
return YES ;
667
+ }
668
+ }
669
+ else
670
+ {
671
+ [completeResults appendFormat: @" Remote %@ is actually not connected, can't check for existing refname there!\n " ,[repoRemotes objectAtIndex: i]];
637
672
}
638
673
}
639
674
}
640
675
676
+ if (result)
677
+ {
678
+ *result = completeResults;
679
+ }
641
680
return NO ;
642
681
}
643
682
644
- - (BOOL )refExistsOnRemote : (PBGitRef *)ref remoteName : (NSString *)remote
683
+
684
+ - (BOOL )refExistsOnRemote : (PBGitRef *)ref remoteName : (NSString *)remote resultMessage : (NSString **)result
645
685
{
646
- if ((!ref) || (![self hasRemotes ]))
686
+ if (!remote)
687
+ {
688
+ if (result)
689
+ {
690
+ *result = @" Remotename is Nil, can't progress check existence!" ;
691
+ }
692
+ return NO ;
693
+ }
694
+
695
+ if (!ref)
647
696
{
697
+ if (result)
698
+ {
699
+ *result = [NSString stringWithFormat: @" Ref is Nil, can't progress check existence on remote %@ !" ,remote];
700
+ }
648
701
return NO ;
649
702
}
650
703
@@ -663,36 +716,112 @@ - (BOOL)refExistsOnRemote:(PBGitRef *)ref remoteName:(NSString *)remote
663
716
refShortName = [ref remoteBranchName ];
664
717
}
665
718
719
+ if (![self hasRemotes ])
720
+ {
721
+ if (result)
722
+ {
723
+ *result = [NSString stringWithFormat: @" Repository has no remotes, can't progress check existence from %@ %@ on remote %@ !" ,[ref refishType ],refShortName,remote];
724
+ }
725
+ return NO ;
726
+ }
727
+
728
+ if (![self isRemoteConnected: remote])
729
+ {
730
+ if (result)
731
+ {
732
+ *result = [NSString stringWithFormat: @" Remote %@ is actually not connected, can't check for existing refname there!" ,remote];
733
+ }
734
+ return NO ;
735
+ }
736
+
666
737
int retValue = 1 ;
667
- // Check remote refs/tags/ and refs/heads for ref
668
- NSArray *arguments = [NSArray arrayWithObjects: @" ls-remote" , @" -t" , @" -h " , remote, refShortName, nil ];
738
+ // Check remote refs/tags/ for ref
739
+ NSArray *arguments = [NSArray arrayWithObjects: @" ls-remote" , @" -t" , remote, refShortName, nil ];
669
740
NSString *output = [self outputInWorkdirForArguments: arguments retValue: &retValue];
670
741
if (![output isEqualToString: @" " ])
742
+ {
743
+ if (result)
744
+ {
745
+ *result = [NSString stringWithFormat: @" %@ exists as tag on remote %@ !" ,refShortName,remote];
746
+ }
671
747
return YES ;
748
+ }
672
749
750
+ // Check remote refs/tags/ for ref
751
+ arguments = [NSArray arrayWithObjects: @" ls-remote" , @" -h" , remote, refShortName, nil ];
752
+ output = [self outputInWorkdirForArguments: arguments retValue: &retValue];
753
+ if (![output isEqualToString: @" " ])
754
+ {
755
+ if (result)
756
+ {
757
+ *result = [NSString stringWithFormat: @" %@ exists as branch on remote %@ !" ,refShortName,remote];
758
+ }
759
+ return YES ;
760
+ }
761
+
673
762
return NO ;
674
763
}
675
764
676
- - (BOOL )refExistsOnAnyRemote : (PBGitRef*)ref
765
+
766
+ - (BOOL )refExistsOnAnyRemote : (PBGitRef*)ref resultMessage : (NSString **)result
677
767
{
678
768
if (!ref)
679
769
{
770
+ if (result)
771
+ {
772
+ *result = @" Ref is Nil, can't progress check existence on any remotes!" ;
773
+ }
680
774
return NO ;
681
775
}
682
-
776
+
777
+ NSMutableString *completeResult = [NSMutableString string ];
778
+
683
779
if ([self hasRemotes ])
684
780
{
685
781
NSArray *repoRemotes = [self remotes ];
782
+ NSString *oneResult;
686
783
for (int i=0 ; i<[repoRemotes count ]; i++)
687
784
{
688
- if ([self refExistsOnRemote: ref remoteName: [repoRemotes objectAtIndex: i]])
785
+ if ([self refExistsOnRemote: ref remoteName: [repoRemotes objectAtIndex: i] resultMessage: &oneResult])
786
+ {
787
+ if (oneResult)
788
+ {
789
+ [completeResult appendString: oneResult];
790
+ }
791
+
792
+ if (result)
793
+ {
794
+ *result = completeResult;
795
+ }
796
+
689
797
return YES ;
798
+ }
799
+ else
800
+ {
801
+ if (oneResult)
802
+ {
803
+ [completeResult appendString: oneResult];
804
+ }
805
+ }
690
806
}
691
807
}
692
-
808
+ else
809
+ {
810
+ if (result)
811
+ {
812
+ *result = [NSString stringWithFormat: @" Repository has no remotes, can't progress check existence from %@ on any remotes!" ,[ref shortName ]];
813
+ }
814
+ return NO ;
815
+ }
816
+
817
+ if (result)
818
+ {
819
+ *result = completeResult;
820
+ }
693
821
return NO ;
694
822
}
695
823
824
+
696
825
- (BOOL )tagExistsOnRemote : (PBGitRef *)ref remoteName : (NSString *)remote
697
826
{
698
827
if ((!ref) || (![self hasRemotes ]) || (![ref isTag ]))
@@ -817,7 +946,7 @@ - (PBGitRef *) remoteRefForBranch:(PBGitRef *)branch error:(NSError **)error
817
946
if (remoteName && ([remoteName isKindOfClass: [NSString class ]] && (![remoteName isEqualToString: @" " ]))) {
818
947
PBGitRef *remoteRef = [PBGitRef refFromString: [kGitXRemoteRefPrefix stringByAppendingString: remoteName]];
819
948
// check that the remote is a valid ref and exists
820
- if ([self checkRefFormat: [remoteRef ref ]] && [self refExists: remoteRef checkOnRemotesWithoutBranches: NO ])
949
+ if ([self checkRefFormat: [remoteRef ref ]] && [self refExists: remoteRef checkOnRemotesWithoutBranches: NO resultMessage: Nil ])
821
950
return remoteRef;
822
951
}
823
952
}
@@ -894,17 +1023,17 @@ - (void) changeRemote:(PBGitRef *)ref toURL:(NSURL*)newUrl;
894
1023
}
895
1024
896
1025
897
- - (BOOL )isRemoteConnected : (PBGitRef *) ref
1026
+ - (BOOL )isRemoteConnected : (NSString *) remoteName
898
1027
{
899
- if ((![ref isRemote ]) || (![[ self remotes ] containsObject: [ref remoteName ]]) )
1028
+ if (! remoteName)
900
1029
return NO ;
901
1030
902
1031
// Send a command to the remote and check the ExitCode
903
1032
int gitRetValue = 1 ;
904
- NSArray *arguments = [NSArray arrayWithObjects: @" ls-remote" , [ref remoteName ] , nil ];
905
- NSLog (@" Start testing connection to remote %@ " ,[ref remoteName ] );
1033
+ NSArray *arguments = [NSArray arrayWithObjects: @" ls-remote" , remoteName, nil ];
1034
+ NSLog (@" Start testing connection to remote %@ " ,remoteName);
906
1035
[self outputInWorkdirForArguments: arguments retValue: &gitRetValue];
907
- NSLog (@" Stop testing connection to remote %@ " ,[ref remoteName ] );
1036
+ NSLog (@" Stop testing connection to remote %@ " ,remoteName);
908
1037
if (gitRetValue)
909
1038
{
910
1039
return NO ;
@@ -1385,10 +1514,10 @@ - (BOOL) deleteRemoteTag:(PBGitRef *)ref
1385
1514
1386
1515
for (int i=0 ; i<[remotes count ]; i++)
1387
1516
{
1388
- if ([self refExistsOnRemote: ref remoteName: [remotes objectAtIndex: i]])
1517
+ if ([self refExistsOnRemote: ref remoteName: [remotes objectAtIndex: i] resultMessage: Nil ])
1389
1518
{
1390
1519
BOOL remoteConnected = YES ;
1391
- if (![self isRemoteConnected: [PBGitRef refFromString: [ NSString stringWithFormat: @" %@%@ " , kGitXRemoteRefPrefix ,[ remotes objectAtIndex: i]] ]])
1520
+ if (![self isRemoteConnected: [remotes objectAtIndex: i]])
1392
1521
{
1393
1522
NSString *info = [NSString stringWithFormat: @" Remote %@ is not conneted!" ,[remotes objectAtIndex: i]];
1394
1523
NSError *error = [NSError errorWithDomain: PBGitRepositoryErrorDomain
@@ -1459,7 +1588,7 @@ - (BOOL) deleteRef:(PBGitRef *)ref
1459
1588
}
1460
1589
else if ([ref refishType ] == kGitXTagType )
1461
1590
{
1462
- if ([self refExistsOnAnyRemote: ref])
1591
+ if ([self refExistsOnAnyRemote: ref resultMessage: Nil ])
1463
1592
{
1464
1593
[self deleteRemoteTag: ref];
1465
1594
}
0 commit comments