Skip commits only for tools
Get rid of accidents like 67feb782f947046f65951303893713052a19a546.
This commit is contained in:
parent
98b409cb9c
commit
6b05f125bb
Notes:
git
2023-03-28 08:18:12 +00:00
@ -583,6 +583,22 @@ module SyncDefaultGems
|
|||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
|
tools = pipe_readlines(%W"git diff --name-only -z HEAD~..HEAD -- test/lib/ tool/")
|
||||||
|
unless tools.empty?
|
||||||
|
system(*%W"git checkout HEAD~ --", *tools)
|
||||||
|
if system(*%W"git diff --quiet HEAD~")
|
||||||
|
`git reset HEAD~ --` && `git checkout .` && `git clean -fd`
|
||||||
|
puts "Skip commit #{sha} only for tools"
|
||||||
|
next
|
||||||
|
end
|
||||||
|
unless system(*%W"git commit --amend --no-edit --", *tools)
|
||||||
|
failed_commits << sha
|
||||||
|
`git reset HEAD~ --` && `git checkout .` && `git clean -fd`
|
||||||
|
puts "Failed to pick #{sha}"
|
||||||
|
next
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
head = `git log --format=%H -1 HEAD`.chomp
|
head = `git log --format=%H -1 HEAD`.chomp
|
||||||
system(*%w"git reset --quiet HEAD~ --")
|
system(*%w"git reset --quiet HEAD~ --")
|
||||||
amend = replace_rdoc_ref_all
|
amend = replace_rdoc_ref_all
|
||||||
|
@ -73,4 +73,77 @@ module Test_SyncDefaultGems
|
|||||||
assert_message_filter(expected, trailers, [expected, "", trailers].join("\n"))
|
assert_message_filter(expected, trailers, [expected, "", trailers].join("\n"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class TestSyncWithCommits < Test::Unit::TestCase
|
||||||
|
def setup
|
||||||
|
super
|
||||||
|
@target = nil
|
||||||
|
pend "No git" unless system("git --version", out: IO::NULL)
|
||||||
|
@testdir = Dir.mktmpdir("sync")
|
||||||
|
@git_config = ENV["GIT_CONFIG_GLOBAL"]
|
||||||
|
ENV["GIT_CONFIG_GLOBAL"] = @testdir + "/gitconfig"
|
||||||
|
system(*%W"git config --global user.email test@ruby-lang.org")
|
||||||
|
system(*%W"git config --global user.name", "Ruby")
|
||||||
|
@target = "sync-test"
|
||||||
|
SyncDefaultGems::REPOSITORIES[@target.to_sym] = ["ruby/#{@target}", "default"]
|
||||||
|
@sha = {}
|
||||||
|
@origdir = Dir.pwd
|
||||||
|
Dir.chdir(@testdir)
|
||||||
|
["src", @target].each do |dir|
|
||||||
|
system(*%W"git init -q -b default #{dir}", exception: true)
|
||||||
|
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)
|
||||||
|
system(*%W"git commit -q -m", "Add tool #{dir}", exception: true, chdir: dir)
|
||||||
|
@sha[dir] = IO.popen(%W[git log --format=%H -1], chdir: dir, &:read).chomp
|
||||||
|
end
|
||||||
|
system(*%W"git remote add #{@target} ../#{@target}", exception: true, chdir: "src")
|
||||||
|
end
|
||||||
|
|
||||||
|
def teardown
|
||||||
|
if @target
|
||||||
|
Dir.chdir(@origdir)
|
||||||
|
SyncDefaultGems::REPOSITORIES.delete(@target.to_sym)
|
||||||
|
ENV["GIT_CONFIG_GLOBAL"] = @git_config
|
||||||
|
FileUtils.rm_rf(@testdir)
|
||||||
|
end
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
|
def capture_process_output_to(outputs)
|
||||||
|
IO.pipe do |r, w|
|
||||||
|
orig = outputs.map {|out| out.dup}
|
||||||
|
outputs.each {|out| out.reopen(w)}
|
||||||
|
w.close
|
||||||
|
reader = Thread.start {r.read}
|
||||||
|
yield
|
||||||
|
ensure
|
||||||
|
outputs.each {|out| o = orig.shift; out.reopen(o); o.close}
|
||||||
|
return reader.value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def capture_process_outputs
|
||||||
|
out = err = nil
|
||||||
|
synchronize do
|
||||||
|
out = capture_process_output_to(STDOUT) do
|
||||||
|
err = capture_process_output_to(STDERR) do
|
||||||
|
yield
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return out, err
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_skip_tool
|
||||||
|
system(*%W"git rm -q tool/ok", exception: true, chdir: @target)
|
||||||
|
system(*%W"git commit -q -m", "Remove tool", 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
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user