The trunk version. The previous implementation is actually broken except
for file renaming.

Index: src/add.c
==================================================================
--- src/add.c
+++ src/add.c
@@ -859,10 +859,12 @@
   int vid;
   int moveFiles;
   int dryRunFlag;
   int softFlag;
   int hardFlag;
+  int origType;
+  int destType;
   char *zDest;
   Blob dest;
   Stmt q;

   db_must_be_within_tree();
@@ -900,15 +902,23 @@
     "UPDATE vfile SET origname=pathname WHERE origname IS NULL;"
   );
   db_multi_exec(
     "CREATE TEMP TABLE mv(f TEXT UNIQUE ON CONFLICT IGNORE, t TEXT);"
   );
-  if( file_isdir(zDest, RepoFILE)!=1 ){
+  if( g.argc!=4 ){
+    origType = -1;
+  }else{
+    origType = (file_isdir(g.argv[2], RepoFILE) == 1);
+  }
+  destType = file_isdir(zDest, RepoFILE);
+  if( origType==-1 && destType!=1 ){
+    usage("OLDNAME NEWNAME");
+  }else if( origType==1 && destType==2 ){
+    fossil_fatal("cannot rename '%s' to '%s' since another file named"
+                 " '%s' exists", g.argv[2], zDest, zDest);
+  }else if( origType==0 && destType!=1 ){
     Blob orig;
-    if( g.argc!=4 ){
-      usage("OLDNAME NEWNAME");
-    }
     file_tree_name(g.argv[2], &orig, 0, 1);
     db_multi_exec(
       "INSERT INTO mv VALUES(%B,%B)", &orig, &dest
     );
   }else{
@@ -936,10 +946,12 @@
         const char *zPath = db_column_text(&q, 0);
         int nPath = db_column_bytes(&q, 0);
         const char *zTail;
         if( nPath==nOrig ){
           zTail = file_tail(zPath);
+        }else if( destType==1 ){
+          zTail = &zPath[nOrig-strlen(file_tail(zOrig))];
         }else{
           zTail = &zPath[nOrig+1];
         }
         db_multi_exec(
           "INSERT INTO mv VALUES('%q','%q%q')",

Index: test/mv-rm.test
==================================================================
--- test/mv-rm.test
+++ test/mv-rm.test
@@ -16,14 +16,10 @@
 ############################################################################
 #
 # MV / RM Commands
 #

-set path [file dirname [info script]]
-
-require_no_open_checkout
-
 ########################################
 # Setup: Add Files and Commit          #
 ########################################

 test_setup; set rootDir [file normalize [pwd]]
@@ -413,21 +409,22 @@
 # Test 18: Move Directory to New Directory #
 ############################################

 fossil mv --hard subdirC subdirD
 test mv-file-new-directory-7 {
-  [normalize_result] eq "RENAME subdirC subdirD\nMOVED_FILE
${rootDir}/subdirC"
+  [normalize_result] eq "RENAME subdirC/f10 subdirD/f10\nRENAME
subdirC/f11 subdirD/f11\nMOVED_FILE ${rootDir}/subdirC/f10\nMOVED_FILE
${rootDir}/subdirC/f11"
 }

 test mv-file-new-directory-8 {[file size subdirD/f10] == 3}
 test mv-file-new-directory-9 {[read_file subdirD/f10] eq "f10"}
 test mv-file-new-directory-10 {[file size subdirD/f11] == 3}
 test mv-file-new-directory-11 {[read_file subdirD/f11] eq "f11"}

 fossil revert
+puts [normalize_result]
 test mv-file-new-directory-12 {
-  [normalize_result] eq "REVERT   subdirC/f10\nREVERT
subdirC/f11${undoMsg}"
+  [normalize_result] eq "DELETE   subdirD/f10\nDELETE
subdirD/f11\nREVERT   subdirC/f10\nREVERT   subdirC/f11${undoMsg}"
 }

 test mv-file-new-directory-13 {[file size subdirC/f10] == 3}
 test mv-file-new-directory-14 {[read_file subdirC/f10] eq "f10"}
 test mv-file-new-directory-15 {[file size subdirC/f11] == 3}



2018-05-06 01:25, Richard Hipp:> On 5/5/18, Dingyuan Wang
<gumb...@aosc.io> wrote:
>>
>> The fossil mv command seems can't rename a directory.
> 
> I thought somebody had fixed that.  But maybe not.  What version are you 
> using?
> 
> Renaming directories, or even files, is not something that I do very
> often, as I find that it disrupts the history of the project, making
> it more difficult to answer questions like "why and when was this line
> of code inserted?"  If the code keeps moving around, it becomes more
> difficult to track which file that line of code started in.  To
> illustrate the infrequency with which I rename files, here is a
> complete list of file rename operations that have occurred on the
> SQLite project during the 8.7 years that it has been tracked by
> Fossil:
> 
>     https://sqlite.org/src/test-rename-list
> 
> That's a short list when you consider that there have been 13616
> check-ins in that same time period.
> 
> The above sounds like I'm making excuses.  I shouldn't be.  Fossil
> *should* rename the directory for you without giving you any grief.
> It should "just work".  I'm sorry that didn't.  That needs to be
> fixed.  (You can submit patches if you like :-))  The purpose of my
> long reply is to point out that renaming is not a frequently used
> feature, and is thus more likely to contain shortcoming and bugs,
> which you have apparently now discovered.
> 
_______________________________________________
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users

Reply via email to