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].
Commit
a70f279a1d256711c0269df7f145244c2cac0e445e47be2df7ba20ed17cac9a9
Parent
8e06863eebaa395…
1 file changed
+27
+27
| --- src/checkin.c | ||
| +++ src/checkin.c | ||
| @@ -2434,10 +2434,12 @@ | ||
| 2434 | 2434 | Blob ans; /* Answer to continuation prompts */ |
| 2435 | 2435 | char cReply; /* First character of ans */ |
| 2436 | 2436 | int bRecheck = 0; /* Repeat fork and closed-branch checks*/ |
| 2437 | 2437 | int bIgnoreSkew = 0; /* --ignore-clock-skew flag */ |
| 2438 | 2438 | int mxSize; |
| 2439 | + char *zCurBranch = 0; /* The current branch name of checkout */ | |
| 2440 | + char *zNewBranch = 0; /* The branch name after update */ | |
| 2439 | 2441 | |
| 2440 | 2442 | memset(&sCiInfo, 0, sizeof(sCiInfo)); |
| 2441 | 2443 | url_proxy_options(); |
| 2442 | 2444 | /* --sha1sum is an undocumented alias for --hash for backwards compatiblity */ |
| 2443 | 2445 | useHash = find_option("hash",0,0)!=0 || find_option("sha1sum",0,0)!=0; |
| @@ -2499,10 +2501,11 @@ | ||
| 2499 | 2501 | if( find_option("ignore-oversize",0,0)!=0 ) mxSize = 0; |
| 2500 | 2502 | verify_all_options(); |
| 2501 | 2503 | |
| 2502 | 2504 | /* Get the ID of the parent manifest artifact */ |
| 2503 | 2505 | vid = db_lget_int("checkout", 0); |
| 2506 | + zCurBranch = branch_of_rid(vid); | |
| 2504 | 2507 | if( vid==0 ){ |
| 2505 | 2508 | useCksum = 1; |
| 2506 | 2509 | if( privateFlag==0 && sCiInfo.zBranch==0 ) { |
| 2507 | 2510 | sCiInfo.zBranch=db_get("main-branch", 0); |
| 2508 | 2511 | } |
| @@ -2713,10 +2716,34 @@ | ||
| 2713 | 2716 | " WHERE tagid=%d AND rid=%d AND tagtype>0" |
| 2714 | 2717 | " AND value=%Q", TAG_BRANCH, vid, sCiInfo.zBranch)) |
| 2715 | 2718 | ){ |
| 2716 | 2719 | fossil_fatal("cannot commit against a closed leaf"); |
| 2717 | 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); | |
| 2718 | 2745 | |
| 2719 | 2746 | /* Always exit the loop on the second pass */ |
| 2720 | 2747 | if( bRecheck ) break; |
| 2721 | 2748 | |
| 2722 | 2749 | |
| 2723 | 2750 |
| --- 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 |