I'm new to the code, but seems the problem is the value stored in the sqlite field last-sync-url.  If you trust url_parse() to set the right g.urlCanonical value, then simply making both clone.c and sync.c store g.urlCanonical in last-sync-url would seem to fix this consistently:

<verbatim>
src]$ fossil diff
Index: src/clone.c
===================================================================
fossil diff
--- src/clone.c
+++ src/clone.c
@@ -56,12 +56,12 @@
     db_record_repository_filename(g.argv[3]);
     db_multi_exec(
       "REPLACE INTO config(name,value)"
       " VALUES('server-code', lower(hex(randomblob(20))));"
       "REPLACE INTO config(name,value)"
-      " VALUES('last-sync-url',
-      g.urlName
+      " VALUES('last-sync-url', '%q');",
+      g.urlCanonical
     );
     g.zLogin = db_text(0, "SELECT login FROM user WHERE cap LIKE '%%s%%'");
     if( g.zLogin==0 ){
       db_create_default_users(1);
     }
@@ -73,11 +73,11 @@
     db_record_repository_filename(g.argv[3]);
     db_initial_setup(0, 0);
     user_select();
     db_set("content-schema", CONTENT_SCHEMA, 0);
     db_set("aux-schema", AUX_SCHEMA, 0);
-    db_set("last-sync-url", g.argv[2], 0);
+    db_set("last-sync-url", g.urlCanonical, 0);
     db_multi_exec(
       "REPLACE INTO config(name,value)"
       " VALUES('server-code', lower(hex(randomblob(20))));"
     );
     url_enable_proxy(0);

Index: src/sync.c
===================================================================
fossil diff
--- src/sync.c
+++ src/sync.c
@@ -83,11 +83,11 @@
   if( zUrl==0 ){
     if( urlOptional ) exit(0);
     usage("URL");
   }
   url_parse(zUrl);
-  db_set("last-sync-url", zUrl, 0);
+  db_set("last-sync-url", g.urlCanonical, 0);
   user_select();
   if( g.argc==2 ){
     if( g.urlPort!=g.urlDfltPort ){
       printf("Server:
               g.urlProtocol, g.urlName, g.urlPort, g.urlPath);

</verbatim>


Another possible tact is to make minimal changes and instead only change 1 line in sync.c:

<verbatim>
work2]$ fossil diff
Index: src/sync.c
===================================================================
fossil diff
--- src/sync.c
+++ src/sync.c
@@ -83,11 +83,11 @@
   if( zUrl==0 ){
     if( urlOptional ) exit(0);
     usage("URL");
   }
   url_parse(zUrl);
-  db_set("last-sync-url", zUrl, 0);
+  db_set("last-sync-url", g.urlIsFile ? g.urlCanonical : zUrl, 0);
   user_select();
   if( g.argc==2 ){
     if( g.urlPort!=g.urlDfltPort ){
       printf("Server:
               g.urlProtocol, g.urlName, g.urlPort, g.urlPath);

</verbatim>


Did I overlook anything?