File tree Expand file tree Collapse file tree 2 files changed +60
-0
lines changed Expand file tree Collapse file tree 2 files changed +60
-0
lines changed Original file line number Diff line number Diff line change @@ -770,6 +770,17 @@ fn fetch_with_cli(
770
770
. arg ( "--update-head-ok" ) // see discussion in #2078
771
771
. arg ( url. to_string ( ) )
772
772
. arg ( refspec)
773
+ // If cargo is run by git (for example, the `exec` command in `git
774
+ // rebase`), the GIT_DIR is set by git and will point to the wrong
775
+ // location (this takes precedence over the cwd). Make sure this is
776
+ // unset so git will look at cwd for the repo.
777
+ . env_remove ( "GIT_DIR" )
778
+ // The reset of these may not be necessary, but I'm including them
779
+ // just to be extra paranoid and avoid any issues.
780
+ . env_remove ( "GIT_WORK_TREE" )
781
+ . env_remove ( "GIT_INDEX_FILE" )
782
+ . env_remove ( "GIT_OBJECT_DIRECTORY" )
783
+ . env_remove ( "GIT_ALTERNATE_OBJECT_DIRECTORIES" )
773
784
. cwd ( repo. path ( ) ) ;
774
785
config
775
786
. shell ( )
Original file line number Diff line number Diff line change @@ -2694,3 +2694,52 @@ fn git_with_cli_force() {
2694
2694
p. cargo ( "build" ) . run ( ) ;
2695
2695
p. rename_run ( "foo" , "foo2" ) . with_stdout ( "two" ) . run ( ) ;
2696
2696
}
2697
+
2698
+ #[ cargo_test]
2699
+ fn git_fetch_cli_env_clean ( ) {
2700
+ if disable_git_cli ( ) {
2701
+ return ;
2702
+ }
2703
+ // This tests that git-fetch-with-cli works when GIT_DIR environment
2704
+ // variable is set (for whatever reason).
2705
+ let git_dep = git:: new ( "dep1" , |project| {
2706
+ project
2707
+ . file ( "Cargo.toml" , & basic_manifest ( "dep1" , "0.5.0" ) )
2708
+ . file ( "src/lib.rs" , "" )
2709
+ } )
2710
+ . unwrap ( ) ;
2711
+
2712
+ let git_proj = git:: new ( "foo" , |project| {
2713
+ project
2714
+ . file (
2715
+ "Cargo.toml" ,
2716
+ & format ! (
2717
+ r#"
2718
+ [package]
2719
+ name = "foo"
2720
+ version = "0.1.0"
2721
+ [dependencies]
2722
+ dep1 = {{ git = '{}' }}
2723
+ "# ,
2724
+ git_dep. url( )
2725
+ ) ,
2726
+ )
2727
+ . file ( "src/lib.rs" , "pub extern crate dep1;" )
2728
+ . file (
2729
+ ".cargo/config" ,
2730
+ "
2731
+ [net]
2732
+ git-fetch-with-cli = true
2733
+ " ,
2734
+ )
2735
+ } )
2736
+ . unwrap ( ) ;
2737
+
2738
+ // The directory set here isn't too important. Pointing to our own git
2739
+ // directory causes git to be confused and fail. Can also point to an
2740
+ // empty directory, or a nonexistent one.
2741
+ git_proj
2742
+ . cargo ( "fetch" )
2743
+ . env ( "GIT_DIR" , git_proj. root ( ) . join ( ".git" ) )
2744
+ . run ( ) ;
2745
+ }
You can’t perform that action at this time.
0 commit comments