From c0c6aaa0c98a0d20aa509aaf195a8a5c23a938ee Mon Sep 17 00:00:00 2001 From: Daniel Mueller Date: Sat, 29 Jun 2019 17:18:18 -0700 Subject: [PATCH] Add patch for dev-lang/rust that fixes git problem in cargo This change adds a patch for a fix in cargo that causes the branches in a git repository for a cargo managed project to potentially be messed up during a rebase --exec cycle when a git fetch is invoked as part of the command being executed. This problem is tracked upstream as issue #7072 [1]. [1] https://github.com/rust-lang/cargo/issues/7072 --- ...ment-when-git-fetch-with-cli-is-used.patch | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 patches/dev-lang/rust/cargo_-_clean-environment-when-git-fetch-with-cli-is-used.patch diff --git a/patches/dev-lang/rust/cargo_-_clean-environment-when-git-fetch-with-cli-is-used.patch b/patches/dev-lang/rust/cargo_-_clean-environment-when-git-fetch-with-cli-is-used.patch new file mode 100644 index 00000000..6fae0dd9 --- /dev/null +++ b/patches/dev-lang/rust/cargo_-_clean-environment-when-git-fetch-with-cli-is-used.patch @@ -0,0 +1,92 @@ +From 00fd31dd9bc757d8b8a3c35466daec09aa965d83 Mon Sep 17 00:00:00 2001 +From: Eric Huss +Date: Sat, 29 Jun 2019 13:32:21 -0700 +Subject: [PATCH] Clean environment when git-fetch-with-cli is used. + +--- + src/cargo/sources/git/utils.rs | 11 ++++++++ + tests/testsuite/git.rs | 49 ++++++++++++++++++++++++++++++++++ + 2 files changed, 60 insertions(+) + +diff --git a/src/tools/cargo/src/cargo/sources/git/utils.rs b/src/tools/cargo/src/cargo/sources/git/utils.rs +index a71e49..5ad3ed 100644 +--- a/src/tools/cargo/src/cargo/sources/git/utils.rs ++++ b/src/tools/cargo/src/cargo/sources/git/utils.rs +@@ -770,6 +770,17 @@ fn fetch_with_cli( + .arg("--update-head-ok") // see discussion in #2078 + .arg(url.to_string()) + .arg(refspec) ++ // If cargo is run by git (for example, the `exec` command in `git ++ // rebase`), the GIT_DIR is set by git and will point to the wrong ++ // location (this takes precedence over the cwd). Make sure this is ++ // unset so git will look at cwd for the repo. ++ .env_remove("GIT_DIR") ++ // The reset of these may not be necessary, but I'm including them ++ // just to be extra paranoid and avoid any issues. ++ .env_remove("GIT_WORK_TREE") ++ .env_remove("GIT_INDEX_FILE") ++ .env_remove("GIT_OBJECT_DIRECTORY") ++ .env_remove("GIT_ALTERNATE_OBJECT_DIRECTORIES") + .cwd(repo.path()); + config + .shell() +diff --git a/src/tools/cargo/tests/testsuite/git.rs b/src/tools/cargo/tests/testsuite/git.rs +index 8cdd3f..9762ea 100644 +--- a/src/tools/cargo/tests/testsuite/git.rs ++++ b/src/tools/cargo/tests/testsuite/git.rs +@@ -2694,3 +2694,52 @@ fn git_with_cli_force() { + p.cargo("build").run(); + p.rename_run("foo", "foo2").with_stdout("two").run(); + } ++ ++#[cargo_test] ++fn git_fetch_cli_env_clean() { ++ if disable_git_cli() { ++ return; ++ } ++ // This tests that git-fetch-with-cli works when GIT_DIR environment ++ // variable is set (for whatever reason). ++ let git_dep = git::new("dep1", |project| { ++ project ++ .file("Cargo.toml", &basic_manifest("dep1", "0.5.0")) ++ .file("src/lib.rs", "") ++ }) ++ .unwrap(); ++ ++ let git_proj = git::new("foo", |project| { ++ project ++ .file( ++ "Cargo.toml", ++ &format!( ++ r#" ++ [package] ++ name = "foo" ++ version = "0.1.0" ++ [dependencies] ++ dep1 = {{ git = '{}' }} ++ "#, ++ git_dep.url() ++ ), ++ ) ++ .file("src/lib.rs", "pub extern crate dep1;") ++ .file( ++ ".cargo/config", ++ " ++ [net] ++ git-fetch-with-cli = true ++ ", ++ ) ++ }) ++ .unwrap(); ++ ++ // The directory set here isn't too important. Pointing to our own git ++ // directory causes git to be confused and fail. Can also point to an ++ // empty directory, or a nonexistent one. ++ git_proj ++ .cargo("fetch") ++ .env("GIT_DIR", git_proj.root().join(".git")) ++ .run(); ++} +-- +2.21.0 +