Check-in [41561125cd]
Not logged in
Overview

SHA1 Hash:41561125cd744d8b1adbc7a7fb6f0cb0a32571a1
Date: 2007-09-26 04:17:37
User: jnc
Comment:Added safemerge option to commit, update and settings
Timelines: ancestors | descendants | both | trunk
Other Links: files | ZIP archive | manifest

Tags And Properties
Changes
[hide diffs]

Modified src/branch.c from [6f4b5c89ef] to [efd61694e3].

@@ -37,11 +37,11 @@
   Blob cksum1, cksum2;   /* Before and after commit checksums */
   Blob cksum1b;          /* Checksum recorded in the manifest */
 
   noSign = find_option("nosign","",0)!=0;
   db_must_be_within_tree();
-  noSign = db_get_int("omit-ci-sig", 0)|noSign;
+  noSign = db_get_int("omit-sign", 0)|noSign;
   zColor = find_option("bgcolor","c",1);
 
   verify_all_options();
 
   /* fossil branch new name */

Modified src/checkin.c from [55cded4432] to [a88de4d022].

@@ -315,11 +315,11 @@
 ** changed will be committed unless some subset of files is specified
 ** on the command line.
 */
 void commit_cmd(void){
   int rc;
-  int vid, nrid, nvid;
+  int vid, nrid, nvid, wouldFork=0;
   Blob comment;
   const char *zComment;
   Stmt q;
   Stmt q2;
   char *zUuid, *zDate;
@@ -335,11 +335,11 @@
 
   noSign = find_option("nosign","",0)!=0;
   zComment = find_option("comment","m",1);
   forceFlag = find_option("force", "r", 0)!=0;
   db_must_be_within_tree();
-  noSign = db_get_int("omit-ci-sig", 0)|noSign;
+  noSign = db_get_int("omit-sign", 0)|noSign;
   verify_all_options();
 
   /*
   ** Autosync if requested.
   */
@@ -382,12 +382,15 @@
       fossil_panic("file %s has not changed", blob_str(&unmodified));
     }
   }
 
   vid = db_lget_int("checkout", 0);
-  if( !forceFlag && db_exists("SELECT 1 FROM plink WHERE pid=%d", vid) ){
-    fossil_fatal("would fork.  use -f or --force");
+  if( db_exists("SELECT 1 FROM plink WHERE pid=%d", vid) ){
+    wouldFork=1;
+    if( forceFlag==0 && db_get_int("safemerge", 0)==0 ){
+      fossil_fatal("would fork.  use -f or --force");
+    }
   }
   vfile_aggregate_checksum_disk(vid, &cksum1);
   if( zComment ){
     blob_zero(&comment);
     blob_append(&comment, zComment, -1);
@@ -534,8 +537,17 @@
   undo_reset();
 
   /* Commit */
   db_end_transaction(0);
 
-  /* Do an autosync push if requested */
-  autosync(0);
+  if( wouldFork==0 ){
+    /* Do an autosync push if requested. If wouldFork == 1, then they either
+    ** forced this commit or safe merge is on, and this commit did indeed
+    ** create a fork. In this case, we want the user to merge before sending
+    ** their new commit back to the rest of the world, so do not auto-push.
+    */
+    autosync(0);
+  }else{
+    printf("Warning: commit caused a fork to occur. Please merge and push\n");
+    printf("         your changes as soon as possible.\n");
+  }
 }

Modified src/db.c from [cfa5a42c54] to [c13c02bc16].

@@ -694,10 +694,11 @@
       "INSERT INTO config(name,value)"
       " VALUES('project-code', lower(hex(randomblob(20))));"
     );
   }
   db_set_int("autosync", 1);
+  db_set_int("safemerge", 0);
   db_set_int("localauth", 0);
   zUser = db_global_get("default-user", 0);
   if( zUser==0 ){
     zUser = getenv("USER");
   }
@@ -918,10 +919,13 @@
 **
 **   editor        Text editor command used for check-in comments.
 **
 **   clear-sign    Command used to clear-sign manifests at check-in.
 **                 The default is "gpg --clearsign -o ".
+**
+**   omit-sign     When enabled, fossil will not attempt to sign any
+**                 commit with gpg. All commits will be unsigned.
 */
 void cmd_config(void){
   db_open_config();
   if( g.argc>2 ){
     int i;
@@ -974,19 +978,24 @@
 **
 **    autosync         If enabled, automatically pull prior to
 **                     commit or update and automatically push
 **                     after commit or tag or branch creation.
 **
-**    localauth        If true, require that HTTP connections from
+**    localauth        If enabled, require that HTTP connections from
 **                     127.0.0.1 be authenticated by password.  If
 **                     false, all HTTP requests from localhost have
 **                     unrestricted access to the repository.
+**
+**    safemerge        If enabled, when commit will cause a fork, the
+**                     commit will not abort with warning. Also update
+**                     will not be allowed if local changes exist.
 */
 void setting_cmd(void){
   static const char *azName[] = {
     "autosync",
-    "localauth"
+    "localauth",
+    "safemerge",
   };
   int i;
   db_find_and_open_repository();
   if( g.argc==2 ){
     for(i=0; i<sizeof(azName)/sizeof(azName[0]); i++){

Modified src/update.c from [1e8d7a1bd1] to [ca0677b5f7].

@@ -65,10 +65,13 @@
     fossil_fatal("cannot find current version");
   }
   if( db_exists("SELECT 1 FROM vmerge") ){
     fossil_fatal("cannot update an uncommitted merge");
   }
+  if( unsaved_changes() && db_get_int("safemerge", 0) ){
+    fossil_fatal("you have uncommitted changes and safemerge is enabled");
+  }
 
   if( g.argc==3 ){
     tid = name_to_rid(g.argv[2]);
     if( tid==0 ){
       fossil_fatal("not a version: %s", g.argv[2]);
@@ -76,12 +79,19 @@
     if( !is_a_version(tid) ){
       fossil_fatal("not a version: %s", g.argv[2]);
     }
   }
 
-  /* Do an autosync pull prior to the update, if autosync is on */
-  autosync(1);
+  if( tid==0 ){
+    /*
+    ** Do an autosync pull prior to the update, if autosync is on and they
+    ** did not want a specific version (i.e. another branch, a past revision).
+    ** By not giving a specific version, they are asking for the latest, thus
+    ** pull to get the latest, then update.
+    */
+    autosync(1);
+  }
 
   if( tid==0 ){
     compute_leaves(vid);
     if( !latestFlag && db_int(0, "SELECT count(*) FROM leaves")>1 ){
       db_prepare(&q,