Skip to content

Commit 37b96d6

Browse files
committed
sync_default_gems.rb: merge only files named as each gem
1 parent dbdd8c2 commit 37b96d6

1 file changed

Lines changed: 10 additions & 15 deletions

File tree

tool/sync_default_gems.rb

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -349,16 +349,6 @@ def sync_default_gems(gem)
349349
end
350350
end
351351

352-
IGNORE_FILE_PATTERN =
353-
/\A(?:[A-Z]\w*\.(?:md|txt)
354-
|[^\/]+\.yml
355-
|\.git.*
356-
|[A-Z]\w+file
357-
|COPYING
358-
)\z|
359-
|rakelib\/
360-
/x
361-
362352
def message_filter(repo, sha)
363353
log = STDIN.read
364354
print "[#{repo}] ", log.sub(/\s*(?=(?i:\nCo-authored-by:.*)*\Z)/) {
@@ -370,6 +360,11 @@ def sync_default_gems_with_commits(gem, ranges, edit: nil)
370360
repo = REPOSITORIES[gem.to_sym]
371361
puts "Sync #{repo} with commit history."
372362

363+
file_pattern = gem == repo ? gem : "{#{gem},#{repo}}"
364+
file_pattern = "*/#{file_pattern}{,.*,/**/*}"
365+
fnm_option = File::FNM_PATHNAME | File::FNM_DOTMATCH
366+
file_match = proc {|file| File.fnmatch?(file_pattern, file, fnm_option)}
367+
373368
IO.popen(%W"git remote") do |f|
374369
unless f.read.split.include?(gem)
375370
`git remote add #{gem} git@github.com:#{repo}.git`
@@ -395,8 +390,9 @@ def sync_default_gems_with_commits(gem, ranges, edit: nil)
395390

396391
# Ignore Merge commit and insufficiency commit for ruby core repository.
397392
commits.delete_if do |sha, subject|
398-
files = IO.popen(%W"git diff-tree --no-commit-id --name-only -r #{sha}", &:readlines)
399-
subject =~ /^Merge/ || subject =~ /^Auto Merge/ || files.all?{|file| file =~ IGNORE_FILE_PATTERN}
393+
next true if /^(?:Auto )?Merge/ =~ subject
394+
IO.popen(%W"git diff-tree --no-commit-id --name-only -r #{sha}", &:read)
395+
.split("\n").none?(&file_match)
400396
end
401397

402398
if commits.empty?
@@ -433,10 +429,9 @@ def sync_default_gems_with_commits(gem, ranges, edit: nil)
433429
if result.empty?
434430
skipped = true
435431
elsif /^CONFLICT/ =~ result
436-
result = IO.popen(%W"git status --porcelain", &:readlines).each(&:chomp!)
437-
result.map! {|line| line[/^.U (.*)/, 1]}
432+
result = IO.popen(%W"git status --porcelain", &:readlines).map! {|line| line[/^.U (.*)/, 1]}
438433
result.compact!
439-
ignore, conflict = result.partition {|name| IGNORE_FILE_PATTERN =~ name}
434+
conflict, ignore = result.partition(&file_match)
440435
unless ignore.empty?
441436
system(*%W"git reset HEAD --", *ignore)
442437
File.unlink(*ignore)

0 commit comments

Comments
 (0)