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