aboutsummaryrefslogtreecommitdiffstats
path: root/tool/sync_default_gems.rb
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2021-04-11 13:18:47 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2021-04-11 13:18:47 +0900
commit37b96d6773a2151fb3193cab6b9e3f7328915844 (patch)
tree84d0cb1c0303296e9a53368ddc92b60ecc340033 /tool/sync_default_gems.rb
parentdbdd8c2dfe229023daed4e00147229a3c7acdad1 (diff)
downloadruby-37b96d6773a2151fb3193cab6b9e3f7328915844.tar.gz
sync_default_gems.rb: merge only files named as each gem
Diffstat (limited to 'tool/sync_default_gems.rb')
-rw-r--r--tool/sync_default_gems.rb25
1 files changed, 10 insertions, 15 deletions
diff --git a/tool/sync_default_gems.rb b/tool/sync_default_gems.rb
index 695ec68ef3..9861a896d0 100644
--- a/tool/sync_default_gems.rb
+++ b/tool/sync_default_gems.rb
@@ -349,16 +349,6 @@ def sync_default_gems(gem)
end
end
-IGNORE_FILE_PATTERN =
- /\A(?:[A-Z]\w*\.(?:md|txt)
- |[^\/]+\.yml
- |\.git.*
- |[A-Z]\w+file
- |COPYING
- )\z|
- |rakelib\/
- /x
-
def message_filter(repo, sha)
log = STDIN.read
print "[#{repo}] ", log.sub(/\s*(?=(?i:\nCo-authored-by:.*)*\Z)/) {
@@ -370,6 +360,11 @@ def sync_default_gems_with_commits(gem, ranges, edit: nil)
repo = REPOSITORIES[gem.to_sym]
puts "Sync #{repo} with commit history."
+ file_pattern = gem == repo ? gem : "{#{gem},#{repo}}"
+ file_pattern = "*/#{file_pattern}{,.*,/**/*}"
+ fnm_option = File::FNM_PATHNAME | File::FNM_DOTMATCH
+ file_match = proc {|file| File.fnmatch?(file_pattern, file, fnm_option)}
+
IO.popen(%W"git remote") do |f|
unless f.read.split.include?(gem)
`git remote add #{gem} git@github.com:#{repo}.git`
@@ -395,8 +390,9 @@ def sync_default_gems_with_commits(gem, ranges, edit: nil)
# Ignore Merge commit and insufficiency commit for ruby core repository.
commits.delete_if do |sha, subject|
- files = IO.popen(%W"git diff-tree --no-commit-id --name-only -r #{sha}", &:readlines)
- subject =~ /^Merge/ || subject =~ /^Auto Merge/ || files.all?{|file| file =~ IGNORE_FILE_PATTERN}
+ next true if /^(?:Auto )?Merge/ =~ subject
+ IO.popen(%W"git diff-tree --no-commit-id --name-only -r #{sha}", &:read)
+ .split("\n").none?(&file_match)
end
if commits.empty?
@@ -433,10 +429,9 @@ def sync_default_gems_with_commits(gem, ranges, edit: nil)
if result.empty?
skipped = true
elsif /^CONFLICT/ =~ result
- result = IO.popen(%W"git status --porcelain", &:readlines).each(&:chomp!)
- result.map! {|line| line[/^.U (.*)/, 1]}
+ result = IO.popen(%W"git status --porcelain", &:readlines).map! {|line| line[/^.U (.*)/, 1]}
result.compact!
- ignore, conflict = result.partition {|name| IGNORE_FILE_PATTERN =~ name}
+ conflict, ignore = result.partition(&file_match)
unless ignore.empty?
system(*%W"git reset HEAD --", *ignore)
File.unlink(*ignore)