Remove files which are newly added but to be ignored

This commit is contained in:
Nobuyoshi Nakada 2023-11-07 09:28:10 +09:00
Родитель a328228591
Коммит 304194d73e
2 изменённых файлов: 24 добавлений и 4 удалений

Просмотреть файл

@ -554,6 +554,10 @@ module SyncDefaultGems
return true
end
def preexisting?(base, file)
system(*%w"git cat-file -e", "#{base}:#{file}", err: File::NULL)
end
def filter_pickup_files(changed, ignore_file_pattern, base)
toplevels = {}
remove = []
@ -561,14 +565,13 @@ module SyncDefaultGems
changed = changed.reject do |f|
case
when toplevels.fetch(top = f[%r[\A[^/]+(?=/|\z)]m]) {
remove << top if toplevels[top] =
!system(*%w"git cat-file -e", "#{base}:#{top}", err: File::NULL)
remove << top if toplevels[top] = !preexisting?(base, top)
}
# Remove any new top-level directories.
true
when ignore_file_pattern.match?(f)
# Forcibly reset any changes matching ignore_file_pattern.
ignore << f
(preexisting?(base, f) ? ignore : remove) << f
end
end
return changed, remove, ignore

Просмотреть файл

@ -246,7 +246,24 @@ module Test_SyncDefaultGems
assert_not_equal(@sha["src"], top_commit("src"), out)
assert_equal("*~\n", File.read("src/.gitignore"), out)
assert_equal("#!/bin/sh\n""echo ok\n", File.read("src/tool/ok"), out)
assert_not_operator(File, :exist?, "src/.github/workflows/.yml", out)
assert_equal(":ok\n""Should.be_merged\n", File.read("src/lib/common.rb"), out)
assert_not_operator(File, :exist?, "src/.github/workflows/main.yml", out)
end
def test_gitignore_after_conflict
File.write("src/Gemfile", "# main\n")
git(*%W"add Gemfile", chdir: "src")
git(*%W"commit -q -m", "Add Gemfile", chdir: "src")
File.write("#@target/Gemfile", "# conflict\n", mode: "a")
File.write("#@target/lib/common.rb", "Should.be_merged\n", mode: "a")
File.write("#@target/.github/workflows/main.yml", "# Should not merge\n", mode: "a")
git(*%W"add Gemfile .github lib/common.rb", chdir: @target)
git(*%W"commit -q -m", "Should be common.rb only", chdir: @target)
out = assert_sync()
assert_not_equal(@sha["src"], top_commit("src"), out)
assert_equal("# main\n", File.read("src/Gemfile"), out)
assert_equal(":ok\n""Should.be_merged\n", File.read("src/lib/common.rb"), out)
assert_not_operator(File, :exist?, "src/.github/workflows/main.yml", out)
end
end
end