Commits

Anonymous committed 49d31f1

Bug fix/changes to support pushing/pulling from repos that have a relative path in the .hgrc file. The original code assumed either absolute file paths or prefixed the path with http:// which was wrong.

See bug #58 Pulling/Pushing from/to local repo fails

  • Participants
  • Parent commits cc411a4

Comments (0)

Files changed (2)

File Source/RepoController_Actions.m

     [sheet orderOut: self];
     if( returnCode != NSOKButton )
         return;
-    
-    NSURL *url = _pushURLField.objectValue;
+
+    // EW: objectValue may now return either an NSURL or NSString due to my changes.
+	// If an NSString is returned, my assumption is that it is a relative path like @"../MySource".
+    id some_value = _pushURLField.objectValue;
+    NSURL *url;
+	
+    // Should only be a NSString holding a relative path or a NSURL
+    if( [some_value isKindOfClass: [NSString class]] ) {
+        NSString* combined_string = [[self.directory stringByAppendingString:some_value] stringByStandardizingPath];
+        url = [NSURL fileURLWithPath:combined_string];
+	} else {
+        url = (NSURL*)some_value;
+	}
     if( ! url )
         return;
-    
+        
     HgTransferOp xferOp = (HgTransferOp)(size_t)context;
     HgTransferOptions options = 0;
     if( _pullUpdateCheckbox.state )

File Source/URLFormatter.m

 }
 
 
-
+// EW: Needed to change implementation to handle relative paths.
+// Because this converted an NSURL (from an original string) to a NSString,
+// the information about whether the path was relative or not was lost.
+// So my changes allow for an NSString to not be converted to a NSURL
+// and then I just return the string if that's the case. This string will
+// be a relative path like @"../MySource".
 - (NSString *)stringForObjectValue:(id)obj
 {
-    if( ! [obj isKindOfClass: [NSURL class]] )
+    if( [obj isKindOfClass: [NSString class]] )
+        return obj;
+    else if( ! [obj isKindOfClass: [NSURL class]] )
         return @"";
     else if( [obj isFileURL] )
         return [obj path];
         *obj = [NSURL fileURLWithPath: str];
         if( ! *obj )
             error = @"Invalid filesystem path";
-    } else {
+    } else if( [str hasPrefix: @".."] ) {
+        /* This check is needed for relative paths, e.g. ../MySource.
+           A better implemention should be added to handle relative paths in the middle of the string.
+		   Instead of returning an NSURL, I return an NSString because this code gets called by
+		   stringForObjectValue which then converts it back to an NSString. The double conversion
+		   was causing information to be lost about whether the NSURL was a relative path or not.
+        */
+        NSString* expanded_string = [str stringByStandardizingPath];
+        *obj = expanded_string;
+        if( ! *obj )
+            error = @"Invalid filesystem path";
+    } else {        
         NSURL *url = [NSURL URLWithString: str];
         NSString *scheme = [url scheme];
         if( url && scheme == nil ) {