@@ -2691,3 +2691,120 @@ fn git_fetch_cli_env_clean() {
26912691 . env ( "GIT_DIR" , git_proj. root ( ) . join ( ".git" ) )
26922692 . run ( ) ;
26932693}
2694+
2695+ #[ cargo_test]
2696+ fn dirty_submodule ( ) {
2697+ // `cargo package` warns for dirty file in submodule.
2698+ let git_project = git:: new ( "foo" , |project| {
2699+ project
2700+ . file ( "Cargo.toml" , & basic_manifest ( "foo" , "0.5.0" ) )
2701+ // This is necessary because `git::add` is too eager.
2702+ . file ( ".gitignore" , "/target" )
2703+ } )
2704+ . unwrap ( ) ;
2705+ let git_project2 = git:: new ( "src" , |project| {
2706+ project. no_manifest ( ) . file ( "lib.rs" , "pub fn f() {}" )
2707+ } )
2708+ . unwrap ( ) ;
2709+
2710+ let repo = git2:: Repository :: open ( & git_project. root ( ) ) . unwrap ( ) ;
2711+ let url = path2url ( git_project2. root ( ) ) . to_string ( ) ;
2712+ git:: add_submodule ( & repo, & url, Path :: new ( "src" ) ) ;
2713+
2714+ // Submodule added, but not committed.
2715+ git_project
2716+ . cargo ( "package --no-verify" )
2717+ . with_status ( 101 )
2718+ . with_stderr (
2719+ "\
2720+ [WARNING] manifest has no [..]
2721+ See [..]
2722+ [ERROR] 1 files in the working directory contain changes that were not yet committed into git:
2723+
2724+ .gitmodules
2725+
2726+ to proceed despite [..]
2727+ " ,
2728+ )
2729+ . run ( ) ;
2730+
2731+ git:: commit ( & repo) ;
2732+ git_project. cargo ( "package --no-verify" ) . run ( ) ;
2733+
2734+ // Modify file, check for warning.
2735+ git_project. change_file ( "src/lib.rs" , "" ) ;
2736+ git_project
2737+ . cargo ( "package --no-verify" )
2738+ . with_status ( 101 )
2739+ . with_stderr (
2740+ "\
2741+ [WARNING] manifest has no [..]
2742+ See [..]
2743+ [ERROR] 1 files in the working directory contain changes that were not yet committed into git:
2744+
2745+ src/lib.rs
2746+
2747+ to proceed despite [..]
2748+ " ,
2749+ )
2750+ . run ( ) ;
2751+ // Commit the change.
2752+ let sub_repo = git2:: Repository :: open ( git_project. root ( ) . join ( "src" ) ) . unwrap ( ) ;
2753+ git:: add ( & sub_repo) ;
2754+ git:: commit ( & sub_repo) ;
2755+ git:: add ( & repo) ;
2756+ git:: commit ( & repo) ;
2757+ git_project. cargo ( "package --no-verify" ) . run ( ) ;
2758+
2759+ // Try with a nested submodule.
2760+ let git_project3 = git:: new ( "bar" , |project| project. no_manifest ( ) . file ( "mod.rs" , "" ) ) . unwrap ( ) ;
2761+ let url = path2url ( git_project3. root ( ) ) . to_string ( ) ;
2762+ git:: add_submodule ( & sub_repo, & url, Path :: new ( "bar" ) ) ;
2763+ git_project
2764+ . cargo ( "package --no-verify" )
2765+ . with_status ( 101 )
2766+ . with_stderr (
2767+ "\
2768+ [WARNING] manifest has no [..]
2769+ See [..]
2770+ [ERROR] 1 files in the working directory contain changes that were not yet committed into git:
2771+
2772+ src/.gitmodules
2773+
2774+ to proceed despite [..]
2775+ " ,
2776+ )
2777+ . run ( ) ;
2778+
2779+ // Commit the submodule addition.
2780+ git:: commit ( & sub_repo) ;
2781+ git:: add ( & repo) ;
2782+ git:: commit ( & repo) ;
2783+ git_project. cargo ( "package --no-verify" ) . run ( ) ;
2784+ // Modify within nested submodule.
2785+ git_project. change_file ( "src/bar/mod.rs" , "//test" ) ;
2786+ git_project
2787+ . cargo ( "package --no-verify" )
2788+ . with_status ( 101 )
2789+ . with_stderr (
2790+ "\
2791+ [WARNING] manifest has no [..]
2792+ See [..]
2793+ [ERROR] 1 files in the working directory contain changes that were not yet committed into git:
2794+
2795+ src/bar/mod.rs
2796+
2797+ to proceed despite [..]
2798+ " ,
2799+ )
2800+ . run ( ) ;
2801+ // And commit the change.
2802+ let sub_sub_repo = git2:: Repository :: open ( git_project. root ( ) . join ( "src/bar" ) ) . unwrap ( ) ;
2803+ git:: add ( & sub_sub_repo) ;
2804+ git:: commit ( & sub_sub_repo) ;
2805+ git:: add ( & sub_repo) ;
2806+ git:: commit ( & sub_repo) ;
2807+ git:: add ( & repo) ;
2808+ git:: commit ( & repo) ;
2809+ git_project. cargo ( "package --no-verify" ) . run ( ) ;
2810+ }
0 commit comments