From 47144f91a176f263f870e05347d5b426efc40293 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Tue, 30 Jul 2019 16:44:29 +0900 Subject: [PATCH] Separate VCS::GIT#upstream --- tool/lib/vcs.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tool/lib/vcs.rb b/tool/lib/vcs.rb index dd6162c8c2..2ecbfbed44 100644 --- a/tool/lib/vcs.rb +++ b/tool/lib/vcs.rb @@ -578,9 +578,7 @@ class VCS IO.copy_stream(r, path) end - def commit(opts = {}) - args = [COMMAND, "push"] - args << "-n" if dryrun + def upstream (branch = cmd_read(%W"#{COMMAND} symbolic-ref --short HEAD")).chomp! (upstream = cmd_read(%W"#{COMMAND} branch --list --format=%(upstream) #{branch}")).chomp! while ref = upstream[%r"\Arefs/heads/(.*)", 1] @@ -589,7 +587,14 @@ class VCS unless %r"\Arefs/remotes/([^/]+)/(.*)" =~ upstream raise "Upstream not found" end - args << $1 << "HEAD:#$2" + [$1, $2] + end + + def commit(opts = {}) + args = [COMMAND, "push"] + args << "-n" if dryrun + remote, branch = upstream + args << remote << "HEAD:#{branch}" if dryrun? STDERR.puts(args.inspect) return true