Skip to content

Instantly share code, notes, and snippets.

@hsbt
Created April 20, 2021 12:23
Show Gist options
  • Save hsbt/0ec61fa5bca24778fa504f4ec25dfd8a to your computer and use it in GitHub Desktop.
Save hsbt/0ec61fa5bca24778fa504f4ec25dfd8a to your computer and use it in GitHub Desktop.
diff --git tool/sync_default_gems.rb tool/sync_default_gems.rb
index 1c697857d0..3b8dd5474d 100644
--- tool/sync_default_gems.rb
+++ tool/sync_default_gems.rb
@@ -353,6 +353,15 @@ def sync_default_gems(gem)
end
end
+IGNORE_FILE_PATTERN =
+ /\A(?:[A-Z]\w*\.(?:md|txt)
+ |[^\/]+\.yml
+ |\.git.*
+ |[A-Z]\w+file
+ |COPYING
+ |rakelib\/
+ )\z/x
+
def message_filter(repo, sha)
log = STDIN.read
print "[#{repo}] ", log.sub(/\s*(?=(?i:\nCo-authored-by:.*)*\Z)/) {
@@ -364,11 +373,6 @@ 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} [email protected]:#{repo}.git`
@@ -394,9 +398,8 @@ 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|
- 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)
+ 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}
end
if commits.empty?
@@ -433,9 +436,10 @@ 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).map! {|line| line[/^.U (.*)/, 1]}
+ result = IO.popen(%W"git status --porcelain", &:readlines).each(&:chomp!)
+ result.map! {|line| line[/^.U (.*)/, 1]}
result.compact!
- conflict, ignore = result.partition(&file_match)
+ ignore, conflict = result.partition {|name| IGNORE_FILE_PATTERN =~ name}
unless ignore.empty?
system(*%W"git reset HEAD --", *ignore)
File.unlink(*ignore)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment