@@ -12,7 +12,9 @@ use std::thread;
12
12
use cargo_test_support:: git:: cargo_uses_gitoxide;
13
13
use cargo_test_support:: paths:: { self , CargoPathExt } ;
14
14
use cargo_test_support:: registry:: Package ;
15
- use cargo_test_support:: { basic_lib_manifest, basic_manifest, git, main_file, path2url, project} ;
15
+ use cargo_test_support:: {
16
+ basic_lib_manifest, basic_manifest, git, git_process, main_file, path2url, project,
17
+ } ;
16
18
use cargo_test_support:: { sleep_ms, t, Project } ;
17
19
18
20
#[ cargo_test]
@@ -3760,3 +3762,133 @@ fn different_user_relative_submodules() {
3760
3762
3761
3763
assert ! ( project. bin( "foo" ) . is_file( ) ) ;
3762
3764
}
3765
+
3766
+ #[ cargo_test]
3767
+ fn git_worktree_with_original_repo_renamed ( ) {
3768
+ let project = project ( ) . build ( ) ;
3769
+ let git_project = git:: new ( "foo" , |project| {
3770
+ project
3771
+ . file (
3772
+ "Cargo.toml" ,
3773
+ r#"
3774
+ [package]
3775
+ name = "foo"
3776
+ version = "0.5.0"
3777
+ edition = "2015"
3778
+ authors = []
3779
+ license = "MIR OR Apache-2.0"
3780
+ description = "A test!"
3781
+ homepage = "https://example.org"
3782
+ documentation = ""
3783
+ repository = "https://example.org"
3784
+ readme = "./README.md"
3785
+ "# ,
3786
+ )
3787
+ . file ( "src/lib.rs" , "" )
3788
+ . file ( "README.md" , "" )
3789
+ } ) ;
3790
+
3791
+ let repo = git2:: Repository :: open ( & git_project. root ( ) ) . unwrap ( ) ;
3792
+ let repo_root = repo. workdir ( ) . unwrap ( ) . parent ( ) . unwrap ( ) ;
3793
+ let opts = git2:: WorktreeAddOptions :: new ( ) ;
3794
+ let _ = repo
3795
+ . worktree ( "bar" , & repo_root. join ( "bar" ) , Some ( & opts) )
3796
+ . unwrap ( ) ;
3797
+
3798
+ // Rename the original repository
3799
+ let new = repo_root. join ( "foo2" ) ;
3800
+ fs:: rename ( & git_project. root ( ) , & new) . unwrap ( ) ;
3801
+
3802
+ project
3803
+ . cargo ( "package --list" )
3804
+ . cwd ( & new)
3805
+ . with_stdout (
3806
+ "\
3807
+ .cargo_vcs_info.json
3808
+ Cargo.toml
3809
+ Cargo.toml.orig
3810
+ README.md
3811
+ src/lib.rs
3812
+ " ,
3813
+ )
3814
+ . run ( ) ;
3815
+
3816
+ project
3817
+ . cargo ( "check" )
3818
+ . cwd ( & new)
3819
+ . with_stderr ( & format ! (
3820
+ "[CHECKING] foo v0.5.0 ([CWD])\n \
3821
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) \
3822
+ in [..]\n "
3823
+ ) )
3824
+ . run ( ) ;
3825
+ }
3826
+
3827
+ #[ cargo_test( requires_git) ]
3828
+ fn git_worktree_with_bare_original_repo ( ) {
3829
+ let project = project ( ) . build ( ) ;
3830
+ let git_project = git:: new ( "foo" , |project| {
3831
+ project
3832
+ . file (
3833
+ "Cargo.toml" ,
3834
+ r#"
3835
+ [package]
3836
+ name = "foo"
3837
+ version = "0.5.0"
3838
+ edition = "2015"
3839
+ authors = []
3840
+ license = "MIR OR Apache-2.0"
3841
+ description = "A test!"
3842
+ homepage = "https://example.org"
3843
+ documentation = ""
3844
+ repository = "https://example.org"
3845
+ readme = "./README.md"
3846
+ "# ,
3847
+ )
3848
+ . file ( "src/lib.rs" , "" )
3849
+ . file ( "README.md" , "" )
3850
+ } ) ;
3851
+
3852
+ // Create a "bare" Git repository.
3853
+ // Keep the `.git` folder and delete the others.
3854
+ let root = git_project. root ( ) ;
3855
+ fs:: remove_file ( & root. join ( "Cargo.toml" ) ) . unwrap ( ) ;
3856
+ fs:: remove_file ( & root. join ( "README.md" ) ) . unwrap ( ) ;
3857
+ fs:: remove_dir_all ( & root. join ( "src" ) ) . unwrap ( ) ;
3858
+ git_process ( "config --bool core.bare true" )
3859
+ . cwd ( & root)
3860
+ . exec ( )
3861
+ . unwrap ( ) ;
3862
+
3863
+ let repo = git2:: Repository :: open ( & root) . unwrap ( ) ;
3864
+ assert ! ( repo. is_bare( ) ) ;
3865
+ let repo_root = root. parent ( ) . unwrap ( ) ;
3866
+ let opts = git2:: WorktreeAddOptions :: new ( ) ;
3867
+ let wt = repo
3868
+ . worktree ( "bar" , & repo_root. join ( "bar" ) , Some ( & opts) )
3869
+ . unwrap ( ) ;
3870
+
3871
+ project
3872
+ . cargo ( "package --list" )
3873
+ . cwd ( wt. path ( ) )
3874
+ . with_stdout (
3875
+ "\
3876
+ .cargo_vcs_info.json
3877
+ Cargo.toml
3878
+ Cargo.toml.orig
3879
+ README.md
3880
+ src/lib.rs
3881
+ " ,
3882
+ )
3883
+ . run ( ) ;
3884
+
3885
+ project
3886
+ . cargo ( "check" )
3887
+ . cwd ( wt. path ( ) )
3888
+ . with_stderr ( & format ! (
3889
+ "[CHECKING] foo v0.5.0 ([CWD])\n \
3890
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) \
3891
+ in [..]\n "
3892
+ ) )
3893
+ . run ( ) ;
3894
+ }
0 commit comments