Skip to content

Commit 332ff94

Browse files
committed
Ensure git checkout works with untracked files (#14428)
Closes #14425.
1 parent ab17a3c commit 332ff94

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ defmodule Mix.SCM.Git do
137137

138138
# Migrate the Git repo
139139
rev = lock_rev || get_origin_opts_rev(opts) || default_branch()
140-
git!(["--git-dir=.git", "checkout", "--quiet", rev])
140+
git!(["--git-dir=.git", "checkout", "--force", "--quiet", rev])
141141

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

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,9 +396,14 @@ defmodule Mix.Tasks.DepsGitTest do
396396
Mix.State.clear_cache()
397397
purge([DepsOnGitRepo.MixProject])
398398

399+
# Write to the checkout location to ensure it is replaced
400+
File.mkdir_p!("deps/deps_on_git_repo/lib")
401+
File.write!("deps/deps_on_git_repo/lib/deps_on_git_repo.ex", "# WILL BE OVERRIDDEN")
402+
399403
Mix.Tasks.Deps.Update.run(["deps_on_git_repo"])
400404
assert File.exists?("deps/git_repo/lib/git_repo.ex")
401405
assert File.read!("mix.lock") =~ last
406+
assert File.read!("deps/deps_on_git_repo/lib/deps_on_git_repo.ex") =~ "GitRepo.hello()"
402407
refute File.exists?("_build/dev/lib/git_repo/.mix/compile.fetch")
403408
end)
404409
after
@@ -423,10 +428,15 @@ defmodule Mix.Tasks.DepsGitTest do
423428
Mix.State.clear_cache()
424429
purge([DepsOnGitRepo.MixProject])
425430

431+
# Write to the checkout location to ensure it is replaced
432+
File.mkdir_p!("deps/deps_on_git_repo/lib")
433+
File.write!("deps/deps_on_git_repo/lib/deps_on_git_repo.ex", "# WILL BE OVERRIDDEN")
434+
426435
Mix.Dep.Lock.write(%{deps_on_git_repo: {:git, fixture_path("deps_on_git_repo"), last, []}})
427436
Mix.Tasks.Deps.Get.run([])
428437
assert File.exists?("deps/git_repo/lib/git_repo.ex")
429438
assert File.read!("mix.lock") =~ last
439+
assert File.read!("deps/deps_on_git_repo/lib/deps_on_git_repo.ex") =~ "GitRepo.hello()"
430440
refute File.exists?("_build/dev/lib/git_repo/.mix/compile.fetch")
431441
end)
432442
after

0 commit comments

Comments
 (0)