Fossil SCM

Add the --if-changes option to "fossil commit" which causes the command to be a no-op if there have not been any changes to the current checkout.

drh 2025-01-11 16:57 trunk
Commit f36695adf3f13bbac5ca5ffba1ad10c721508ef906fb537508290e3165fb5333
1 file changed +10 -1
+10 -1
--- src/checkin.c
+++ src/checkin.c
@@ -2354,10 +2354,12 @@
23542354
** --close Close the branch being committed
23552355
** --date-override DATETIME DATE to use instead of 'now'
23562356
** --delta Use a delta manifest in the commit process
23572357
** --hash Verify file status using hashing rather
23582358
** than relying on file mtimes
2359
+** --if-changes Make this command a silent no-op if there
2360
+** are no changes
23592361
** --ignore-clock-skew If a clock skew is detected, ignore it and
23602362
** behave as if the user had entered 'yes' to
23612363
** the question of whether to proceed despite
23622364
** the skew.
23632365
** --ignore-oversize Do not warn the user about oversized files
@@ -2409,10 +2411,11 @@
24092411
int forceFlag = 0; /* Undocumented: Disables all checks */
24102412
int forceDelta = 0; /* Force a delta-manifest */
24112413
int forceBaseline = 0; /* Force a baseline-manifest */
24122414
int allowConflict = 0; /* Allow unresolve merge conflicts */
24132415
int allowEmpty = 0; /* Allow a commit with no changes */
2416
+ int onlyIfChanges = 0; /* No-op if there are no changes */
24142417
int allowFork = 0; /* Allow the commit to fork */
24152418
int allowOlder = 0; /* Allow a commit older than its ancestor */
24162419
char *zManifestFile; /* Name of the manifest file */
24172420
int useCksum; /* True if checksums should be computed and verified */
24182421
int outputManifest; /* True to output "manifest" and "manifest.uuid" */
@@ -2466,10 +2469,11 @@
24662469
}
24672470
zComment = find_option("comment","m",1);
24682471
forceFlag = find_option("force", "f", 0)!=0;
24692472
allowConflict = find_option("allow-conflict",0,0)!=0;
24702473
allowEmpty = find_option("allow-empty",0,0)!=0;
2474
+ onlyIfChanges = find_option("if-changes",0,0)!=0;
24712475
allowFork = find_option("allow-fork",0,0)!=0;
24722476
if( find_option("override-lock",0,0)!=0 ) allowFork = 1;
24732477
allowOlder = find_option("allow-older",0,0)!=0;
24742478
noPrompt = find_option("no-prompt", 0, 0)!=0;
24752479
noWarningFlag = find_option("no-warnings", 0, 0)!=0;
@@ -2581,10 +2585,16 @@
25812585
if( nTag ){
25822586
int i;
25832587
for(i=0; i<nTag; i++) sCiInfo.azTag[i] = mprintf("%F", sCiInfo.azTag[i]);
25842588
qsort((void*)sCiInfo.azTag, nTag, sizeof(sCiInfo.azTag[0]), tagCmp);
25852589
}
2590
+
2591
+ hasChanges = unsaved_changes(useHash ? CKSIG_HASH : 0);
2592
+ if( hasChanges==0 && onlyIfChanges ){
2593
+ /* "fossil commit --if-changes" is a no-op if there are no changes. */
2594
+ return;
2595
+ }
25862596
25872597
/*
25882598
** Autosync if autosync is enabled and this is not a private check-in.
25892599
*/
25902600
if( !g.markPrivate ){
@@ -2686,11 +2696,10 @@
26862696
"'%s' was renamed to '%s'", zFrom, zTo, zFrom, zTo);
26872697
}
26882698
db_finalize(&q);
26892699
}
26902700
2691
- hasChanges = unsaved_changes(useHash ? CKSIG_HASH : 0);
26922701
db_begin_transaction();
26932702
db_record_repository_filename(0);
26942703
if( hasChanges==0 && !isAMerge && !allowEmpty && !forceFlag ){
26952704
fossil_fatal("nothing has changed; use --allow-empty to override");
26962705
}
26972706
--- src/checkin.c
+++ src/checkin.c
@@ -2354,10 +2354,12 @@
2354 ** --close Close the branch being committed
2355 ** --date-override DATETIME DATE to use instead of 'now'
2356 ** --delta Use a delta manifest in the commit process
2357 ** --hash Verify file status using hashing rather
2358 ** than relying on file mtimes
 
 
2359 ** --ignore-clock-skew If a clock skew is detected, ignore it and
2360 ** behave as if the user had entered 'yes' to
2361 ** the question of whether to proceed despite
2362 ** the skew.
2363 ** --ignore-oversize Do not warn the user about oversized files
@@ -2409,10 +2411,11 @@
2409 int forceFlag = 0; /* Undocumented: Disables all checks */
2410 int forceDelta = 0; /* Force a delta-manifest */
2411 int forceBaseline = 0; /* Force a baseline-manifest */
2412 int allowConflict = 0; /* Allow unresolve merge conflicts */
2413 int allowEmpty = 0; /* Allow a commit with no changes */
 
2414 int allowFork = 0; /* Allow the commit to fork */
2415 int allowOlder = 0; /* Allow a commit older than its ancestor */
2416 char *zManifestFile; /* Name of the manifest file */
2417 int useCksum; /* True if checksums should be computed and verified */
2418 int outputManifest; /* True to output "manifest" and "manifest.uuid" */
@@ -2466,10 +2469,11 @@
2466 }
2467 zComment = find_option("comment","m",1);
2468 forceFlag = find_option("force", "f", 0)!=0;
2469 allowConflict = find_option("allow-conflict",0,0)!=0;
2470 allowEmpty = find_option("allow-empty",0,0)!=0;
 
2471 allowFork = find_option("allow-fork",0,0)!=0;
2472 if( find_option("override-lock",0,0)!=0 ) allowFork = 1;
2473 allowOlder = find_option("allow-older",0,0)!=0;
2474 noPrompt = find_option("no-prompt", 0, 0)!=0;
2475 noWarningFlag = find_option("no-warnings", 0, 0)!=0;
@@ -2581,10 +2585,16 @@
2581 if( nTag ){
2582 int i;
2583 for(i=0; i<nTag; i++) sCiInfo.azTag[i] = mprintf("%F", sCiInfo.azTag[i]);
2584 qsort((void*)sCiInfo.azTag, nTag, sizeof(sCiInfo.azTag[0]), tagCmp);
2585 }
 
 
 
 
 
 
2586
2587 /*
2588 ** Autosync if autosync is enabled and this is not a private check-in.
2589 */
2590 if( !g.markPrivate ){
@@ -2686,11 +2696,10 @@
2686 "'%s' was renamed to '%s'", zFrom, zTo, zFrom, zTo);
2687 }
2688 db_finalize(&q);
2689 }
2690
2691 hasChanges = unsaved_changes(useHash ? CKSIG_HASH : 0);
2692 db_begin_transaction();
2693 db_record_repository_filename(0);
2694 if( hasChanges==0 && !isAMerge && !allowEmpty && !forceFlag ){
2695 fossil_fatal("nothing has changed; use --allow-empty to override");
2696 }
2697
--- src/checkin.c
+++ src/checkin.c
@@ -2354,10 +2354,12 @@
2354 ** --close Close the branch being committed
2355 ** --date-override DATETIME DATE to use instead of 'now'
2356 ** --delta Use a delta manifest in the commit process
2357 ** --hash Verify file status using hashing rather
2358 ** than relying on file mtimes
2359 ** --if-changes Make this command a silent no-op if there
2360 ** are no changes
2361 ** --ignore-clock-skew If a clock skew is detected, ignore it and
2362 ** behave as if the user had entered 'yes' to
2363 ** the question of whether to proceed despite
2364 ** the skew.
2365 ** --ignore-oversize Do not warn the user about oversized files
@@ -2409,10 +2411,11 @@
2411 int forceFlag = 0; /* Undocumented: Disables all checks */
2412 int forceDelta = 0; /* Force a delta-manifest */
2413 int forceBaseline = 0; /* Force a baseline-manifest */
2414 int allowConflict = 0; /* Allow unresolve merge conflicts */
2415 int allowEmpty = 0; /* Allow a commit with no changes */
2416 int onlyIfChanges = 0; /* No-op if there are no changes */
2417 int allowFork = 0; /* Allow the commit to fork */
2418 int allowOlder = 0; /* Allow a commit older than its ancestor */
2419 char *zManifestFile; /* Name of the manifest file */
2420 int useCksum; /* True if checksums should be computed and verified */
2421 int outputManifest; /* True to output "manifest" and "manifest.uuid" */
@@ -2466,10 +2469,11 @@
2469 }
2470 zComment = find_option("comment","m",1);
2471 forceFlag = find_option("force", "f", 0)!=0;
2472 allowConflict = find_option("allow-conflict",0,0)!=0;
2473 allowEmpty = find_option("allow-empty",0,0)!=0;
2474 onlyIfChanges = find_option("if-changes",0,0)!=0;
2475 allowFork = find_option("allow-fork",0,0)!=0;
2476 if( find_option("override-lock",0,0)!=0 ) allowFork = 1;
2477 allowOlder = find_option("allow-older",0,0)!=0;
2478 noPrompt = find_option("no-prompt", 0, 0)!=0;
2479 noWarningFlag = find_option("no-warnings", 0, 0)!=0;
@@ -2581,10 +2585,16 @@
2585 if( nTag ){
2586 int i;
2587 for(i=0; i<nTag; i++) sCiInfo.azTag[i] = mprintf("%F", sCiInfo.azTag[i]);
2588 qsort((void*)sCiInfo.azTag, nTag, sizeof(sCiInfo.azTag[0]), tagCmp);
2589 }
2590
2591 hasChanges = unsaved_changes(useHash ? CKSIG_HASH : 0);
2592 if( hasChanges==0 && onlyIfChanges ){
2593 /* "fossil commit --if-changes" is a no-op if there are no changes. */
2594 return;
2595 }
2596
2597 /*
2598 ** Autosync if autosync is enabled and this is not a private check-in.
2599 */
2600 if( !g.markPrivate ){
@@ -2686,11 +2696,10 @@
2696 "'%s' was renamed to '%s'", zFrom, zTo, zFrom, zTo);
2697 }
2698 db_finalize(&q);
2699 }
2700
 
2701 db_begin_transaction();
2702 db_record_repository_filename(0);
2703 if( hasChanges==0 && !isAMerge && !allowEmpty && !forceFlag ){
2704 fossil_fatal("nothing has changed; use --allow-empty to override");
2705 }
2706

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button