Fossil SCM

Check the tagxref table for changes to branch name before commit and if there exists a change that wasn't made by the current user then prompt.

andybradford 2024-12-01 01:44 show-branch-change
Commit 0aabb6bcacd627eb428602647ca6b099cf8209694ab2f799052eca12461a0354
1 file changed +42 -9
+42 -9
--- src/checkin.c
+++ src/checkin.c
@@ -2501,20 +2501,61 @@
25012501
if( find_option("ignore-oversize",0,0)!=0 ) mxSize = 0;
25022502
verify_all_options();
25032503
25042504
/* Get the ID of the parent manifest artifact */
25052505
vid = db_lget_int("checkout", 0);
2506
- zCurBranch = branch_of_rid(vid);
25072506
if( vid==0 ){
25082507
useCksum = 1;
25092508
if( privateFlag==0 && sCiInfo.zBranch==0 ) {
25102509
sCiInfo.zBranch=db_get("main-branch", 0);
25112510
}
25122511
}else{
25132512
privateParent = content_is_private(vid);
25142513
}
25152514
2515
+ user_select();
2516
+ /*
2517
+ ** Check that the user exists.
2518
+ */
2519
+ if( !db_exists("SELECT 1 FROM user WHERE login=%Q", g.zLogin) ){
2520
+ fossil_fatal("no such user: %s", g.zLogin);
2521
+ }
2522
+
2523
+ /*
2524
+ ** Detect if the branch name has changed from the parent check-in
2525
+ ** and prompt if necessary
2526
+ **/
2527
+ zCurBranch = db_text(0,
2528
+ " SELECT value FROM tagxref AS tx"
2529
+ " WHERE rid=(SELECT pid"
2530
+ " FROM tagxref LEFT JOIN event ON srcid=objid"
2531
+ " LEFT JOIN plink ON rid=cid"
2532
+ " WHERE rid=%d AND tagxref.tagid=%d"
2533
+ " AND srcid!=origid"
2534
+ " AND tagtype>0 AND coalesce(euser,user)!=%Q)"
2535
+ " AND tx.tagid=%d",
2536
+ vid, TAG_BRANCH, g.zLogin, TAG_BRANCH
2537
+ );
2538
+ if( zCurBranch!=0 && zCurBranch[0]!=0
2539
+ && forceFlag==0
2540
+ && noPrompt==0
2541
+ ){
2542
+ zNewBranch = branch_of_rid(vid);
2543
+ fossil_warning("parent check-in [%.10s] branch changed from '%s' to '%s'",
2544
+ rid_to_uuid(vid), zCurBranch, zNewBranch);
2545
+ prompt_user("continue (y/N)? ", &ans);
2546
+ cReply = blob_str(&ans)[0];
2547
+ blob_reset(&ans);
2548
+ if( cReply!='y' && cReply!='Y' ){
2549
+ fossil_fatal("Abandoning commit because branch has changed");
2550
+ }
2551
+ fossil_free(zNewBranch);
2552
+ fossil_free(zCurBranch);
2553
+ zCurBranch = branch_of_rid(vid);
2554
+ }
2555
+ if( zCurBranch==0 ) zCurBranch = branch_of_rid(vid);
2556
+
25162557
/* Track the "private" status */
25172558
g.markPrivate = privateFlag || privateParent;
25182559
if( privateFlag && !privateParent ){
25192560
/* Apply default branch name ("private") and color ("orange") if not
25202561
** specified otherwise on the command-line, and if the parent is not
@@ -2642,18 +2683,10 @@
26422683
"'%s' was renamed to '%s'", zFrom, zTo, zFrom, zTo);
26432684
}
26442685
db_finalize(&q);
26452686
}
26462687
2647
- user_select();
2648
- /*
2649
- ** Check that the user exists.
2650
- */
2651
- if( !db_exists("SELECT 1 FROM user WHERE login=%Q", g.zLogin) ){
2652
- fossil_fatal("no such user: %s", g.zLogin);
2653
- }
2654
-
26552688
hasChanges = unsaved_changes(useHash ? CKSIG_HASH : 0);
26562689
db_begin_transaction();
26572690
db_record_repository_filename(0);
26582691
if( hasChanges==0 && !isAMerge && !allowEmpty && !forceFlag ){
26592692
fossil_fatal("nothing has changed; use --allow-empty to override");
26602693
--- src/checkin.c
+++ src/checkin.c
@@ -2501,20 +2501,61 @@
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 }
2512 }else{
2513 privateParent = content_is_private(vid);
2514 }
2515
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2516 /* Track the "private" status */
2517 g.markPrivate = privateFlag || privateParent;
2518 if( privateFlag && !privateParent ){
2519 /* Apply default branch name ("private") and color ("orange") if not
2520 ** specified otherwise on the command-line, and if the parent is not
@@ -2642,18 +2683,10 @@
2642 "'%s' was renamed to '%s'", zFrom, zTo, zFrom, zTo);
2643 }
2644 db_finalize(&q);
2645 }
2646
2647 user_select();
2648 /*
2649 ** Check that the user exists.
2650 */
2651 if( !db_exists("SELECT 1 FROM user WHERE login=%Q", g.zLogin) ){
2652 fossil_fatal("no such user: %s", g.zLogin);
2653 }
2654
2655 hasChanges = unsaved_changes(useHash ? CKSIG_HASH : 0);
2656 db_begin_transaction();
2657 db_record_repository_filename(0);
2658 if( hasChanges==0 && !isAMerge && !allowEmpty && !forceFlag ){
2659 fossil_fatal("nothing has changed; use --allow-empty to override");
2660
--- src/checkin.c
+++ src/checkin.c
@@ -2501,20 +2501,61 @@
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 if( vid==0 ){
2507 useCksum = 1;
2508 if( privateFlag==0 && sCiInfo.zBranch==0 ) {
2509 sCiInfo.zBranch=db_get("main-branch", 0);
2510 }
2511 }else{
2512 privateParent = content_is_private(vid);
2513 }
2514
2515 user_select();
2516 /*
2517 ** Check that the user exists.
2518 */
2519 if( !db_exists("SELECT 1 FROM user WHERE login=%Q", g.zLogin) ){
2520 fossil_fatal("no such user: %s", g.zLogin);
2521 }
2522
2523 /*
2524 ** Detect if the branch name has changed from the parent check-in
2525 ** and prompt if necessary
2526 **/
2527 zCurBranch = db_text(0,
2528 " SELECT value FROM tagxref AS tx"
2529 " WHERE rid=(SELECT pid"
2530 " FROM tagxref LEFT JOIN event ON srcid=objid"
2531 " LEFT JOIN plink ON rid=cid"
2532 " WHERE rid=%d AND tagxref.tagid=%d"
2533 " AND srcid!=origid"
2534 " AND tagtype>0 AND coalesce(euser,user)!=%Q)"
2535 " AND tx.tagid=%d",
2536 vid, TAG_BRANCH, g.zLogin, TAG_BRANCH
2537 );
2538 if( zCurBranch!=0 && zCurBranch[0]!=0
2539 && forceFlag==0
2540 && noPrompt==0
2541 ){
2542 zNewBranch = branch_of_rid(vid);
2543 fossil_warning("parent check-in [%.10s] branch changed from '%s' to '%s'",
2544 rid_to_uuid(vid), zCurBranch, zNewBranch);
2545 prompt_user("continue (y/N)? ", &ans);
2546 cReply = blob_str(&ans)[0];
2547 blob_reset(&ans);
2548 if( cReply!='y' && cReply!='Y' ){
2549 fossil_fatal("Abandoning commit because branch has changed");
2550 }
2551 fossil_free(zNewBranch);
2552 fossil_free(zCurBranch);
2553 zCurBranch = branch_of_rid(vid);
2554 }
2555 if( zCurBranch==0 ) zCurBranch = branch_of_rid(vid);
2556
2557 /* Track the "private" status */
2558 g.markPrivate = privateFlag || privateParent;
2559 if( privateFlag && !privateParent ){
2560 /* Apply default branch name ("private") and color ("orange") if not
2561 ** specified otherwise on the command-line, and if the parent is not
@@ -2642,18 +2683,10 @@
2683 "'%s' was renamed to '%s'", zFrom, zTo, zFrom, zTo);
2684 }
2685 db_finalize(&q);
2686 }
2687
 
 
 
 
 
 
 
 
2688 hasChanges = unsaved_changes(useHash ? CKSIG_HASH : 0);
2689 db_begin_transaction();
2690 db_record_repository_filename(0);
2691 if( hasChanges==0 && !isAMerge && !allowEmpty && !forceFlag ){
2692 fossil_fatal("nothing has changed; use --allow-empty to override");
2693

Keyboard Shortcuts

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