diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2023-11-07 09:28:10 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2023-11-07 10:45:02 +0900 |
commit | 304194d73e3b74b2493bfae16ce6189046f911f5 (patch) | |
tree | b234f524c8c1382a87c20ec466c06fff6bd7478e /tool | |
parent | a3282285916421d2e357e3527b4141a902210a10 (diff) | |
download | ruby-304194d73e3b74b2493bfae16ce6189046f911f5.tar.gz |
Remove files which are newly added but to be ignored
Diffstat (limited to 'tool')
-rwxr-xr-x | tool/sync_default_gems.rb | 9 | ||||
-rwxr-xr-x | tool/test/test_sync_default_gems.rb | 19 |
2 files changed, 24 insertions, 4 deletions
diff --git a/tool/sync_default_gems.rb b/tool/sync_default_gems.rb index 729c74b8e6..db541522a0 100755 --- a/tool/sync_default_gems.rb +++ b/tool/sync_default_gems.rb @@ -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 diff --git a/tool/test/test_sync_default_gems.rb b/tool/test/test_sync_default_gems.rb index b48b51bb52..d4a7b7fe7c 100755 --- a/tool/test/test_sync_default_gems.rb +++ b/tool/test/test_sync_default_gems.rb @@ -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 |