Exclude files added to the toplevel

This commit is contained in:
Nobuyoshi Nakada 2023-08-06 09:26:20 +09:00
Родитель af13b03817
Коммит 3651f985f0
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 3582D74E1FEE4465
2 изменённых файлов: 59 добавлений и 6 удалений

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

@ -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}"

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

@ -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