Fossil SCM

If the branch name changes during a commit, prompt user to confirm continue (behaves similar to other pre-commit checks). Inspired by [forum:d5a1b209186552dd | forum post d5a1b209186552dd].

andybradford 2024-11-27 19:28 UTC show-branch-change
Commit a70f279a1d256711c0269df7f145244c2cac0e445e47be2df7ba20ed17cac9a9
1 file changed +27
--- src/checkin.c
+++ src/checkin.c
@@ -2434,10 +2434,12 @@
24342434
Blob ans; /* Answer to continuation prompts */
24352435
char cReply; /* First character of ans */
24362436
int bRecheck = 0; /* Repeat fork and closed-branch checks*/
24372437
int bIgnoreSkew = 0; /* --ignore-clock-skew flag */
24382438
int mxSize;
2439
+ char *zCurBranch = 0; /* The current branch name of checkout */
2440
+ char *zNewBranch = 0; /* The branch name after update */
24392441
24402442
memset(&sCiInfo, 0, sizeof(sCiInfo));
24412443
url_proxy_options();
24422444
/* --sha1sum is an undocumented alias for --hash for backwards compatiblity */
24432445
useHash = find_option("hash",0,0)!=0 || find_option("sha1sum",0,0)!=0;
@@ -2499,10 +2501,11 @@
24992501
if( find_option("ignore-oversize",0,0)!=0 ) mxSize = 0;
25002502
verify_all_options();
25012503
25022504
/* Get the ID of the parent manifest artifact */
25032505
vid = db_lget_int("checkout", 0);
2506
+ zCurBranch = branch_of_rid(vid);
25042507
if( vid==0 ){
25052508
useCksum = 1;
25062509
if( privateFlag==0 && sCiInfo.zBranch==0 ) {
25072510
sCiInfo.zBranch=db_get("main-branch", 0);
25082511
}
@@ -2713,10 +2716,34 @@
27132716
" WHERE tagid=%d AND rid=%d AND tagtype>0"
27142717
" AND value=%Q", TAG_BRANCH, vid, sCiInfo.zBranch))
27152718
){
27162719
fossil_fatal("cannot commit against a closed leaf");
27172720
}
2721
+
2722
+ /* Require confirmation to continue with the check-in if the branch
2723
+ ** has changed and the committer did not provide the same branch
2724
+ */
2725
+ zNewBranch = branch_of_rid(vid);
2726
+ if( fossil_strcmp(zCurBranch, zNewBranch)!=0
2727
+ && fossil_strcmp(sCiInfo.zBranch, zNewBranch)!=0
2728
+ ){
2729
+ fossil_warning("parent check-in [%.10s] changed branch from '%s' to '%s'",
2730
+ rid_to_uuid(vid), zCurBranch, zNewBranch);
2731
+ if( !noPrompt ){
2732
+ prompt_user("continue (y/N)? ", &ans);
2733
+ cReply = blob_str(&ans)[0];
2734
+ blob_reset(&ans);
2735
+ }else{
2736
+ cReply = 'N';
2737
+ }
2738
+ if( cReply!='y' && cReply!='Y' ){
2739
+ fossil_fatal("Abandoning commit because branch has changed");
2740
+ }
2741
+ fossil_free(zCurBranch);
2742
+ zCurBranch = branch_of_rid(vid);
2743
+ }
2744
+ fossil_free(zNewBranch);
27182745
27192746
/* Always exit the loop on the second pass */
27202747
if( bRecheck ) break;
27212748
27222749
27232750
--- src/checkin.c
+++ src/checkin.c
@@ -2434,10 +2434,12 @@
2434 Blob ans; /* Answer to continuation prompts */
2435 char cReply; /* First character of ans */
2436 int bRecheck = 0; /* Repeat fork and closed-branch checks*/
2437 int bIgnoreSkew = 0; /* --ignore-clock-skew flag */
2438 int mxSize;
 
 
2439
2440 memset(&sCiInfo, 0, sizeof(sCiInfo));
2441 url_proxy_options();
2442 /* --sha1sum is an undocumented alias for --hash for backwards compatiblity */
2443 useHash = find_option("hash",0,0)!=0 || find_option("sha1sum",0,0)!=0;
@@ -2499,10 +2501,11 @@
2499 if( find_option("ignore-oversize",0,0)!=0 ) mxSize = 0;
2500 verify_all_options();
2501
2502 /* Get the ID of the parent manifest artifact */
2503 vid = db_lget_int("checkout", 0);
 
2504 if( vid==0 ){
2505 useCksum = 1;
2506 if( privateFlag==0 && sCiInfo.zBranch==0 ) {
2507 sCiInfo.zBranch=db_get("main-branch", 0);
2508 }
@@ -2713,10 +2716,34 @@
2713 " WHERE tagid=%d AND rid=%d AND tagtype>0"
2714 " AND value=%Q", TAG_BRANCH, vid, sCiInfo.zBranch))
2715 ){
2716 fossil_fatal("cannot commit against a closed leaf");
2717 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2718
2719 /* Always exit the loop on the second pass */
2720 if( bRecheck ) break;
2721
2722
2723
--- src/checkin.c
+++ src/checkin.c
@@ -2434,10 +2434,12 @@
2434 Blob ans; /* Answer to continuation prompts */
2435 char cReply; /* First character of ans */
2436 int bRecheck = 0; /* Repeat fork and closed-branch checks*/
2437 int bIgnoreSkew = 0; /* --ignore-clock-skew flag */
2438 int mxSize;
2439 char *zCurBranch = 0; /* The current branch name of checkout */
2440 char *zNewBranch = 0; /* The branch name after update */
2441
2442 memset(&sCiInfo, 0, sizeof(sCiInfo));
2443 url_proxy_options();
2444 /* --sha1sum is an undocumented alias for --hash for backwards compatiblity */
2445 useHash = find_option("hash",0,0)!=0 || find_option("sha1sum",0,0)!=0;
@@ -2499,10 +2501,11 @@
2501 if( find_option("ignore-oversize",0,0)!=0 ) mxSize = 0;
2502 verify_all_options();
2503
2504 /* Get the ID of the parent manifest artifact */
2505 vid = db_lget_int("checkout", 0);
2506 zCurBranch = branch_of_rid(vid);
2507 if( vid==0 ){
2508 useCksum = 1;
2509 if( privateFlag==0 && sCiInfo.zBranch==0 ) {
2510 sCiInfo.zBranch=db_get("main-branch", 0);
2511 }
@@ -2713,10 +2716,34 @@
2716 " WHERE tagid=%d AND rid=%d AND tagtype>0"
2717 " AND value=%Q", TAG_BRANCH, vid, sCiInfo.zBranch))
2718 ){
2719 fossil_fatal("cannot commit against a closed leaf");
2720 }
2721
2722 /* Require confirmation to continue with the check-in if the branch
2723 ** has changed and the committer did not provide the same branch
2724 */
2725 zNewBranch = branch_of_rid(vid);
2726 if( fossil_strcmp(zCurBranch, zNewBranch)!=0
2727 && fossil_strcmp(sCiInfo.zBranch, zNewBranch)!=0
2728 ){
2729 fossil_warning("parent check-in [%.10s] changed branch from '%s' to '%s'",
2730 rid_to_uuid(vid), zCurBranch, zNewBranch);
2731 if( !noPrompt ){
2732 prompt_user("continue (y/N)? ", &ans);
2733 cReply = blob_str(&ans)[0];
2734 blob_reset(&ans);
2735 }else{
2736 cReply = 'N';
2737 }
2738 if( cReply!='y' && cReply!='Y' ){
2739 fossil_fatal("Abandoning commit because branch has changed");
2740 }
2741 fossil_free(zCurBranch);
2742 zCurBranch = branch_of_rid(vid);
2743 }
2744 fossil_free(zNewBranch);
2745
2746 /* Always exit the loop on the second pass */
2747 if( bRecheck ) break;
2748
2749
2750

Keyboard Shortcuts

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