summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2023-08-06 09:26:20 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2023-08-06 09:26:20 +0900
commit3651f985f0d950b636b3b75528855a25293c48b6 (patch)
treeccacc37ebff814612921b1e71a5fa83818152ba5
parentaf13b03817307a13aa4c93b6d05ce65ac7691059 (diff)
Exclude files added to the toplevel
-rwxr-xr-xtool/sync_default_gems.rb28
-rwxr-xr-xtool/test/test_sync_default_gems.rb37
2 files changed, 59 insertions, 6 deletions
diff --git a/tool/sync_default_gems.rb b/tool/sync_default_gems.rb
index cac3bec766..081ff63c39 100755
--- a/tool/sync_default_gems.rb
+++ b/tool/sync_default_gems.rb
@@ -436,8 +436,8 @@ module SyncDefaultGems
|\.git.*
|[A-Z]\w+file
|COPYING
- |\Arakelib\/.*
- |\Atest\/lib\/.*
+ |rakelib\/.*
+ |test\/lib\/.*
)\z/mx
def message_filter(repo, sha, input: ARGF)
@@ -586,16 +586,32 @@ module SyncDefaultGems
next
end
- tools = pipe_readlines(%W"git diff --name-only -z HEAD~..HEAD -- test/lib/ tool/ rakelib/")
+ changed = pipe_readlines(%W"git diff --name-only -z HEAD~..HEAD --")
+ toplevels = changed.map {|f| f[%r[\A(?!tool/)[^/]+/?]]}.compact
+ toplevels.delete_if do |top|
+ if system(*%w"git checkout -f HEAD~ --", top, err: File::NULL)
+ # previously existent path
+ system(*%w"git checkout -f HEAD --", top, out: File::NULL)
+ true
+ end
+ end
+ unless toplevels.empty?
+ puts "Remove files added to toplevel: #{toplevels.join(', ')}"
+ system(*%w"git rm -r --", *toplevels)
+ end
+ tools = changed.select {|f|f.start_with?("test/lib/", "tool/")}
unless tools.empty?
- system(*%W"git rm --", *tools)
+ system(*%W"git rm -r --", *tools)
system(*%W"git checkout HEAD~ --", *tools)
+ end
+ unless toplevels.empty? and tools.empty?
+ clean = toplevels + tools
if system(*%W"git diff --quiet HEAD~")
`git reset HEAD~ --` && `git checkout .` && `git clean -fd`
- puts "Skip commit #{sha} only for tools"
+ puts "Skip commit #{sha} only for tools or toplevel"
next
end
- unless system(*%W"git commit --amend --no-edit --", *tools)
+ unless system(*%W"git commit --amend --no-edit --", *clean)
failed_commits << sha
`git reset HEAD~ --` && `git checkout .` && `git clean -fd`
puts "Failed to pick #{sha}"
diff --git a/tool/test/test_sync_default_gems.rb b/tool/test/test_sync_default_gems.rb
index 39eab3f205..aa72dcfb20 100755
--- a/tool/test/test_sync_default_gems.rb
+++ b/tool/test/test_sync_default_gems.rb
@@ -93,6 +93,12 @@ module Test_SyncDefaultGems
Dir.chdir(@testdir)
["src", @target].each do |dir|
system(*%W"git init -q #{dir}", exception: true)
+ if dir == "src"
+ Dir.mkdir("#{dir}/lib")
+ File.write("#{dir}/lib/fine.rb", "return\n")
+ system(*%W"git add lib/fine.rb", exception: true, chdir: dir)
+ system(*%W"git commit -q -m", "Looks fine", exception: true, chdir: dir)
+ end
Dir.mkdir("#{dir}/tool")
File.write("#{dir}/tool/ok", "#!/bin/sh\n""echo ok\n")
system(*%W"git add tool/ok", exception: true, chdir: dir)
@@ -147,5 +153,36 @@ module Test_SyncDefaultGems
end
assert_equal(@sha["src"], IO.popen(%W[git log --format=%H -1], chdir: "src", &:read).chomp, out)
end
+
+ def test_skip_toplevel
+ Dir.mkdir("#@target/docs")
+ File.write("#@target/docs/NEWS.md", "= NEWS!!!\n")
+ system(*%W"git add --", "docs/NEWS.md", exception: true, chdir: @target)
+ system(*%W"git commit -q -m", "It's a news", exception: true, chdir: @target)
+ out = capture_process_output_to([STDOUT, STDERR]) do
+ Dir.chdir("src") do
+ SyncDefaultGems.sync_default_gems_with_commits(@target, true)
+ end
+ end
+ assert_equal(@sha["src"], IO.popen(%W[git log --format=%H -1], chdir: "src", &:read).chomp, out)
+ end
+
+ def test_adding_toplevel
+ Dir.mkdir("#@target/docs")
+ File.write("#@target/docs/NEWS.md", "= New library\n")
+ Dir.mkdir("#@target/lib")
+ File.write("#@target/lib/news.rb", "return\n")
+ system(*%W"git add --", "docs/NEWS.md", "lib/news.rb", exception: true, chdir: @target)
+ system(*%W"git commit -q -m", "New lib", exception: true, chdir: @target)
+ out = capture_process_output_to([STDOUT, STDERR]) do
+ Dir.chdir("src") do
+ SyncDefaultGems.sync_default_gems_with_commits(@target, true)
+ end
+ end
+ assert_not_equal(@sha["src"], IO.popen(%W[git log --format=%H -1], chdir: "src", &:read).chomp, out)
+ assert_equal "return\n", File.read("src/lib/news.rb")
+ assert_include IO.popen(%W[git log -1 --oneline], chdir: "src", &:read), "[ruby/#{@target}] New lib"
+ assert_not_operator File, :exist?, "src/docs"
+ end
end
end