aboutsummaryrefslogtreecommitdiffstats
path: root/tool
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2023-09-20 10:32:44 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2023-09-20 13:00:18 +0900
commit3c11cdbcfe5ebcf430b0cdfefb0b92724eebe543 (patch)
tree8782049aa95dcae1b9ae17d8ce9c3d418e15922d /tool
parentafaa164a058209e64dc2bedadc1fd932136d8ae5 (diff)
downloadruby-3c11cdbcfe5ebcf430b0cdfefb0b92724eebe543.tar.gz
Fix the case of file to be ignored with to be removed
The case of 7fc73ab5f6fbe46655855079954b26dcc14576b3, which modified `.gitignore` and `.github/workflows/main.yml`. Both files need to be rejected and restored, but since the latter file was not there before, `git checkout` failed and the former file could not be restored along with it. To fix this failure, restore the ignored files one by one.
Diffstat (limited to 'tool')
-rwxr-xr-xtool/sync_default_gems.rb2
-rwxr-xr-xtool/test/test_sync_default_gems.rb19
2 files changed, 19 insertions, 2 deletions
diff --git a/tool/sync_default_gems.rb b/tool/sync_default_gems.rb
index 5f8a73448e..d14adf0a91 100755
--- a/tool/sync_default_gems.rb
+++ b/tool/sync_default_gems.rb
@@ -596,7 +596,7 @@ module SyncDefaultGems
unless ignore.empty?
puts "Reset ignored files: #{ignore.join(', ')}"
system(*%W"git rm -r --", *ignore)
- system(*%W"git checkout -f", base, "--", *ignore)
+ ignore.each {|f| system(*%W"git checkout -f", base, "--", f)}
end
if changed.empty?
diff --git a/tool/test/test_sync_default_gems.rb b/tool/test/test_sync_default_gems.rb
index 32647b32a1..489feb2894 100755
--- a/tool/test/test_sync_default_gems.rb
+++ b/tool/test/test_sync_default_gems.rb
@@ -97,7 +97,10 @@ module Test_SyncDefaultGems
File.write("#{dir}/.gitignore", "*~\n")
Dir.mkdir("#{dir}/lib")
File.write("#{dir}/lib/common.rb", ":ok\n")
- git(*%W"add .gitignore lib/common.rb", chdir: dir)
+ Dir.mkdir("#{dir}/.github")
+ Dir.mkdir("#{dir}/.github/workflows")
+ File.write("#{dir}/.github/workflows/default.yml", "default:\n")
+ git(*%W"add .gitignore lib/common.rb .github", chdir: dir)
git(*%W"commit -q -m", "Initialize", chdir: dir)
if dir == "src"
File.write("#{dir}/lib/fine.rb", "return\n")
@@ -222,5 +225,19 @@ module Test_SyncDefaultGems
assert_include top_commit("src", format: "oneline"), "[ruby/#{@target}] New lib"
assert_not_operator File, :exist?, "src/docs"
end
+
+ def test_gitignore
+ File.write("#@target/.gitignore", "*.bak\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 .github", chdir: @target)
+ git(*%W"commit -q -m", "Should be common.rb only",
+ *%W".gitignore lib/common.rb .github", chdir: @target)
+ out = assert_sync()
+ 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)
+ end
end
end