diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-07-12 23:40:27 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-07-12 23:41:06 +0900 |
commit | 162d08b8541167a089b2c504d3437b577c38c3f9 (patch) | |
tree | 2f4d42b1623eb43b2191f11f1ae4123c9a43193e /tool | |
parent | 99a9c3fe2eaab8157765d792dc871da6daea0327 (diff) |
sync_default_gems.rb: Added -e option to edit when conflicted
Diffstat (limited to 'tool')
-rw-r--r-- | tool/sync_default_gems.rb | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/tool/sync_default_gems.rb b/tool/sync_default_gems.rb index da41f1aa25..4cd8ddb5d6 100644 --- a/tool/sync_default_gems.rb +++ b/tool/sync_default_gems.rb @@ -313,7 +313,7 @@ end IGNORE_FILE_PATTERN = /\A(?:\.travis.yml|appveyor\.yml|azure-pipelines\.yml|\.git(?:ignore|hub)|Gemfile|README\.md|History\.txt|Rakefile|CODE_OF_CONDUCT\.md)/ -def sync_default_gems_with_commits(gem, ranges) +def sync_default_gems_with_commits(gem, ranges, edit: nil) puts "Sync #{$repositories[gem.to_sym]} with commit history." IO.popen(%W"git remote") do |f| @@ -363,12 +363,24 @@ def sync_default_gems_with_commits(gem, ranges) skipped = true elsif /^CONFLICT/ =~ result result = IO.popen(%W"git status --porcelain", &:readlines).each(&:chomp!) - ignore = result.map {|line| /^.U / =~ line and IGNORE_FILE_PATTERN =~ (name = $') and name} - ignore.compact! + result.map! {|line| line[/^.U (.*)/, 1]} + result.compact! + ignore, conflict = result.partition {|name| IGNORE_FILE_PATTERN =~ name} unless ignore.empty? system(*%W"git reset HEAD --", *ignore) system(*%W"git checkout HEAD --", *ignore) end + unless conflict.empty? + if edit + case + when (editor = ENV["GIT_EDITOR"] and !editor.empty?) + when (editor = `git config core.editor` and (editor.chomp!; !editor.empty?)) + end + if editor + system([editor, conflict].join(' ')) + end + end + end skipped = !system({"GIT_EDITOR"=>"true"}, *%W"git cherry-pick --no-edit --continue") end @@ -469,9 +481,13 @@ when nil, "-h", "--help" exit else + if ARGV[0] == "-e" + edit = true + ARGV.shift + end gem = ARGV.shift if ARGV[0] - sync_default_gems_with_commits(gem, ARGV) + sync_default_gems_with_commits(gem, ARGV, edit: edit) else sync_default_gems(gem) end |