@@ -517,6 +517,8 @@ struct IgnoreList {
517
517
ignore : Vec < String > ,
518
518
/// mercurial formatted entries
519
519
hg_ignore : Vec < String > ,
520
+ /// Fossil-formatted entries.
521
+ fossil_ignore : Vec < String > ,
520
522
}
521
523
522
524
impl IgnoreList {
@@ -525,22 +527,25 @@ impl IgnoreList {
525
527
IgnoreList {
526
528
ignore : Vec :: new ( ) ,
527
529
hg_ignore : Vec :: new ( ) ,
530
+ fossil_ignore : Vec :: new ( ) ,
528
531
}
529
532
}
530
533
531
- /// add a new entry to the ignore list. Requires two arguments with the
532
- /// entry in two different formats. One for "git style" entries and one for
533
- /// "mercurial like " entries.
534
- fn push ( & mut self , ignore : & str , hg_ignore : & str ) {
534
+ /// Add a new entry to the ignore list. Requires three arguments with the
535
+ /// entry in possibly three different formats. One for "git style" entries,
536
+ /// one for "mercurial style" entries and one for "fossil style " entries.
537
+ fn push ( & mut self , ignore : & str , hg_ignore : & str , fossil_ignore : & str ) {
535
538
self . ignore . push ( ignore. to_string ( ) ) ;
536
539
self . hg_ignore . push ( hg_ignore. to_string ( ) ) ;
540
+ self . fossil_ignore . push ( fossil_ignore. to_string ( ) ) ;
537
541
}
538
542
539
543
/// Return the correctly formatted content of the ignore file for the given
540
544
/// version control system as `String`.
541
545
fn format_new ( & self , vcs : VersionControl ) -> String {
542
546
let ignore_items = match vcs {
543
547
VersionControl :: Hg => & self . hg_ignore ,
548
+ VersionControl :: Fossil => & self . fossil_ignore ,
544
549
_ => & self . ignore ,
545
550
} ;
546
551
@@ -557,20 +562,30 @@ impl IgnoreList {
557
562
558
563
let ignore_items = match vcs {
559
564
VersionControl :: Hg => & self . hg_ignore ,
565
+ VersionControl :: Fossil => & self . fossil_ignore ,
560
566
_ => & self . ignore ,
561
567
} ;
562
568
563
- let mut out = "\n \n # Added by cargo\n " . to_string ( ) ;
564
- if ignore_items
565
- . iter ( )
566
- . any ( |item| existing_items. contains ( item) )
567
- {
568
- out. push_str ( "#\n # already existing elements were commented out\n " ) ;
569
+ let mut out = String :: new ( ) ;
570
+
571
+ // Fossil does not support `#` comments.
572
+ if vcs != VersionControl :: Fossil {
573
+ out. push_str ( "\n \n # Added by cargo\n " ) ;
574
+ if ignore_items
575
+ . iter ( )
576
+ . any ( |item| existing_items. contains ( item) )
577
+ {
578
+ out. push_str ( "#\n # already existing elements were commented out\n " ) ;
579
+ }
580
+ out. push ( '\n' ) ;
569
581
}
570
- out. push ( '\n' ) ;
571
582
572
583
for item in ignore_items {
573
584
if existing_items. contains ( item) {
585
+ if vcs == VersionControl :: Fossil {
586
+ // Just merge for Fossil.
587
+ continue ;
588
+ }
574
589
out. push ( '#' ) ;
575
590
}
576
591
out. push_str ( item) ;
@@ -584,30 +599,35 @@ impl IgnoreList {
584
599
/// Writes the ignore file to the given directory. If the ignore file for the
585
600
/// given vcs system already exists, its content is read and duplicate ignore
586
601
/// file entries are filtered out.
587
- fn write_ignore_file (
588
- base_path : & Path ,
589
- list : & IgnoreList ,
590
- vcs : VersionControl ,
591
- ) -> CargoResult < String > {
592
- let fp_ignore = match vcs {
593
- VersionControl :: Git => base_path. join ( ".gitignore" ) ,
594
- VersionControl :: Hg => base_path. join ( ".hgignore" ) ,
595
- VersionControl :: Pijul => base_path. join ( ".ignore" ) ,
596
- VersionControl :: Fossil => return Ok ( "" . to_string ( ) ) ,
597
- VersionControl :: NoVcs => return Ok ( "" . to_string ( ) ) ,
598
- } ;
602
+ fn write_ignore_file ( base_path : & Path , list : & IgnoreList , vcs : VersionControl ) -> CargoResult < ( ) > {
603
+ // Fossil only supports project-level settings in a dedicated subdirectory.
604
+ if vcs == VersionControl :: Fossil {
605
+ paths:: create_dir_all ( base_path. join ( ".fossil-settings" ) ) ?;
606
+ }
599
607
600
- let ignore: String = match paths:: open ( & fp_ignore) {
601
- Err ( err) => match err. downcast_ref :: < std:: io:: Error > ( ) {
602
- Some ( io_err) if io_err. kind ( ) == ErrorKind :: NotFound => list. format_new ( vcs) ,
603
- _ => return Err ( err) ,
604
- } ,
605
- Ok ( file) => list. format_existing ( BufReader :: new ( file) , vcs) ,
606
- } ;
608
+ for fp_ignore in match vcs {
609
+ VersionControl :: Git => vec ! [ base_path. join( ".gitignore" ) ] ,
610
+ VersionControl :: Hg => vec ! [ base_path. join( ".hgignore" ) ] ,
611
+ VersionControl :: Pijul => vec ! [ base_path. join( ".ignore" ) ] ,
612
+ // Fossil has a cleaning functionality configured in a separate file.
613
+ VersionControl :: Fossil => vec ! [
614
+ base_path. join( ".fossil-settings/ignore-glob" ) ,
615
+ base_path. join( ".fossil-settings/clean-glob" ) ,
616
+ ] ,
617
+ VersionControl :: NoVcs => return Ok ( ( ) ) ,
618
+ } {
619
+ let ignore: String = match paths:: open ( & fp_ignore) {
620
+ Err ( err) => match err. downcast_ref :: < std:: io:: Error > ( ) {
621
+ Some ( io_err) if io_err. kind ( ) == ErrorKind :: NotFound => list. format_new ( vcs) ,
622
+ _ => return Err ( err) ,
623
+ } ,
624
+ Ok ( file) => list. format_existing ( BufReader :: new ( file) , vcs) ,
625
+ } ;
607
626
608
- paths:: append ( & fp_ignore, ignore. as_bytes ( ) ) ?;
627
+ paths:: append ( & fp_ignore, ignore. as_bytes ( ) ) ?;
628
+ }
609
629
610
- Ok ( ignore )
630
+ Ok ( ( ) )
611
631
}
612
632
613
633
/// Initializes the correct VCS system based on the provided config.
@@ -650,12 +670,12 @@ fn mk(config: &Config, opts: &MkOptions<'_>) -> CargoResult<()> {
650
670
let name = opts. name ;
651
671
let cfg = config. get :: < CargoNewConfig > ( "cargo-new" ) ?;
652
672
653
- // Using the push method with two arguments ensures that the entries for
654
- // both `ignore` and `hgignore` are in sync.
673
+ // Using the push method with multiple arguments ensures that the entries
674
+ // for all mutually-incompatible VCS in terms of syntax are in sync.
655
675
let mut ignore = IgnoreList :: new ( ) ;
656
- ignore. push ( "/target" , "^target/" ) ;
676
+ ignore. push ( "/target" , "^target/" , "target" ) ;
657
677
if !opts. bin {
658
- ignore. push ( "Cargo.lock" , "glob:Cargo.lock" ) ;
678
+ ignore. push ( "Cargo.lock" , "glob:Cargo.lock" , "Cargo.lock,*/Cargo.lock" ) ;
659
679
}
660
680
661
681
let vcs = opts. version_control . unwrap_or_else ( || {
0 commit comments