Skip to content

Commit 641ac05

Browse files
authored
Ensure git checkout works with untracked files (#14428)
Closes #14425.
1 parent e967d58 commit 641ac05

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/mix/lib/mix/scm/git.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ defmodule Mix.SCM.Git do
141141

142142
# Migrate the Git repo
143143
rev = lock_rev || get_origin_opts_rev(opts) || default_branch()
144-
git!(["--git-dir=.git", "checkout", "--quiet", rev])
144+
git!(["--git-dir=.git", "checkout", "--force", "--quiet", rev])
145145

146146
if opts[:submodules] do
147147
git!(~w[-c core.hooksPath='' --git-dir=.git submodule update --init --recursive])

lib/mix/test/mix/tasks/deps.git_test.exs

+10
Original file line numberDiff line numberDiff line change
@@ -400,9 +400,14 @@ defmodule Mix.Tasks.DepsGitTest do
400400
Mix.State.clear_cache()
401401
purge([DepsOnGitRepo.MixProject])
402402

403+
# Write to the checkout location to ensure it is replaced
404+
File.mkdir_p!("deps/deps_on_git_repo/lib")
405+
File.write!("deps/deps_on_git_repo/lib/deps_on_git_repo.ex", "# WILL BE OVERRIDDEN")
406+
403407
Mix.Tasks.Deps.Update.run(["deps_on_git_repo"])
404408
assert File.exists?("deps/git_repo/lib/git_repo.ex")
405409
assert File.read!("mix.lock") =~ last
410+
assert File.read!("deps/deps_on_git_repo/lib/deps_on_git_repo.ex") =~ "GitRepo.hello()"
406411
refute File.exists?("_build/dev/lib/git_repo/.mix/compile.fetch")
407412
end)
408413
after
@@ -427,10 +432,15 @@ defmodule Mix.Tasks.DepsGitTest do
427432
Mix.State.clear_cache()
428433
purge([DepsOnGitRepo.MixProject])
429434

435+
# Write to the checkout location to ensure it is replaced
436+
File.mkdir_p!("deps/deps_on_git_repo/lib")
437+
File.write!("deps/deps_on_git_repo/lib/deps_on_git_repo.ex", "# WILL BE OVERRIDDEN")
438+
430439
Mix.Dep.Lock.write(%{deps_on_git_repo: {:git, fixture_path("deps_on_git_repo"), last, []}})
431440
Mix.Tasks.Deps.Get.run([])
432441
assert File.exists?("deps/git_repo/lib/git_repo.ex")
433442
assert File.read!("mix.lock") =~ last
443+
assert File.read!("deps/deps_on_git_repo/lib/deps_on_git_repo.ex") =~ "GitRepo.hello()"
434444
refute File.exists?("_build/dev/lib/git_repo/.mix/compile.fetch")
435445
end)
436446
after

0 commit comments

Comments
 (0)