@@ -68,6 +68,8 @@ struct checkout_opts {
68
68
int empty_pathspec_ok ;
69
69
int checkout_index ;
70
70
int checkout_worktree ;
71
+ const char * ignore_unmerged_opt ;
72
+ int ignore_unmerged ;
71
73
72
74
const char * new_branch ;
73
75
const char * new_branch_force ;
@@ -409,17 +411,19 @@ static int checkout_paths(const struct checkout_opts *opts,
409
411
if (opts -> new_branch_log )
410
412
die (_ ("'%s' cannot be used with updating paths" ), "-l" );
411
413
412
- if (opts -> force && opts -> patch_mode )
413
- die (_ ("'%s' cannot be used with updating paths" ), "-f" );
414
+ if (opts -> ignore_unmerged && opts -> patch_mode )
415
+ die (_ ("'%s' cannot be used with updating paths" ),
416
+ opts -> ignore_unmerged_opt );
414
417
415
418
if (opts -> force_detach )
416
419
die (_ ("'%s' cannot be used with updating paths" ), "--detach" );
417
420
418
421
if (opts -> merge && opts -> patch_mode )
419
422
die (_ ("'%s' cannot be used with %s" ), "--merge" , "--patch" );
420
423
421
- if (opts -> force && opts -> merge )
422
- die (_ ("'%s' cannot be used with %s" ), "-f" , "-m" );
424
+ if (opts -> ignore_unmerged && opts -> merge )
425
+ die (_ ("'%s' cannot be used with %s" ),
426
+ opts -> ignore_unmerged_opt , "-m" );
423
427
424
428
if (opts -> new_branch )
425
429
die (_ ("Cannot update paths and switch to branch '%s' at the same time." ),
@@ -495,8 +499,9 @@ static int checkout_paths(const struct checkout_opts *opts,
495
499
if (ce -> ce_flags & CE_MATCHED ) {
496
500
if (!ce_stage (ce ))
497
501
continue ;
498
- if (opts -> force ) {
499
- warning (_ ("path '%s' is unmerged" ), ce -> name );
502
+ if (opts -> ignore_unmerged ) {
503
+ if (!opts -> quiet )
504
+ warning (_ ("path '%s' is unmerged" ), ce -> name );
500
505
} else if (opts -> writeout_stage ) {
501
506
errs |= check_stage (opts -> writeout_stage , ce , pos , opts -> overlay_mode );
502
507
} else if (opts -> merge ) {
@@ -1414,8 +1419,6 @@ static struct option *add_common_options(struct checkout_opts *opts,
1414
1419
"checkout" , "control recursive updating of submodules" ,
1415
1420
PARSE_OPT_OPTARG , option_parse_recurse_submodules_worktree_updater },
1416
1421
OPT_BOOL (0 , "progress" , & opts -> show_progress , N_ ("force progress reporting" )),
1417
- OPT__FORCE (& opts -> force , N_ ("force checkout (throw away local modifications)" ),
1418
- PARSE_OPT_NOCOMPLETE ),
1419
1422
OPT_BOOL ('m' , "merge" , & opts -> merge , N_ ("perform a 3-way merge with the new branch" )),
1420
1423
OPT_STRING (0 , "conflict" , & opts -> conflict_style , N_ ("style" ),
1421
1424
N_ ("conflict style (merge or diff3)" )),
@@ -1433,6 +1436,8 @@ static struct option *add_common_switch_branch_options(
1433
1436
OPT_BOOL ('d' , "detach" , & opts -> force_detach , N_ ("detach HEAD at named commit" )),
1434
1437
OPT_SET_INT ('t' , "track" , & opts -> track , N_ ("set upstream info for new branch" ),
1435
1438
BRANCH_TRACK_EXPLICIT ),
1439
+ OPT__FORCE (& opts -> force , N_ ("force checkout (throw away local modifications)" ),
1440
+ PARSE_OPT_NOCOMPLETE ),
1436
1441
OPT_STRING (0 , "orphan" , & opts -> new_orphan_branch , N_ ("new-branch" ), N_ ("new unparented branch" )),
1437
1442
OPT_BOOL_F (0 , "overwrite-ignore" , & opts -> overwrite_ignore ,
1438
1443
N_ ("update ignored files (default)" ),
@@ -1502,8 +1507,11 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
1502
1507
opts -> merge = 1 ; /* implied */
1503
1508
git_xmerge_config ("merge.conflictstyle" , opts -> conflict_style , NULL );
1504
1509
}
1505
- if (opts -> force )
1510
+ if (opts -> force ) {
1506
1511
opts -> discard_changes = 1 ;
1512
+ opts -> ignore_unmerged_opt = "--force" ;
1513
+ opts -> ignore_unmerged = 1 ;
1514
+ }
1507
1515
1508
1516
if ((!!opts -> new_branch + !!opts -> new_branch_force + !!opts -> new_orphan_branch ) > 1 )
1509
1517
die (_ ("-b, -B and --orphan are mutually exclusive" ));
@@ -1750,6 +1758,8 @@ int cmd_restore(int argc, const char **argv, const char *prefix)
1750
1758
N_ ("restore the index" )),
1751
1759
OPT_BOOL ('W' , "worktree" , & opts .checkout_worktree ,
1752
1760
N_ ("restore the working tree (default)" )),
1761
+ OPT_BOOL (0 , "ignore-unmerged" , & opts .ignore_unmerged ,
1762
+ N_ ("ignore unmerged entries" )),
1753
1763
OPT_BOOL (0 , "overlay" , & opts .overlay_mode , N_ ("use overlay mode" )),
1754
1764
OPT_END ()
1755
1765
};
@@ -1762,6 +1772,7 @@ int cmd_restore(int argc, const char **argv, const char *prefix)
1762
1772
opts .overlay_mode = 0 ;
1763
1773
opts .checkout_index = -1 ; /* default off */
1764
1774
opts .checkout_worktree = -2 ; /* default on */
1775
+ opts .ignore_unmerged_opt = "--ignore-unmerged" ;
1765
1776
1766
1777
options = parse_options_dup (restore_options );
1767
1778
options = add_common_options (& opts , options );
0 commit comments