Module: Command::RemoteClient
Constant Summary collapse
- REF_LINE =
/^([0-9a-f]+) (.*)$/
- ZERO_OID =
"0" * 40
Instance Method Summary collapse
- #build_agent_command(program, url) ⇒ Object
- #recv_references ⇒ Object
- #report_range_update(ref_names, old_oid, new_oid, is_ff) ⇒ Object
- #report_ref_update(ref_names, error, old_oid = nil, new_oid = nil, is_ff = false) ⇒ Object
- #show_ref_update(flag, summary, ref_names, reason = nil) ⇒ Object
- #ssh_command(uri, argv) ⇒ Object
- #start_agent(name, program, url, capabilities = []) ⇒ Object
Instance Method Details
#build_agent_command(program, url) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/command/shared/remote_client.rb', line 19 def build_agent_command(program, url) uri = URI.parse(url) argv = Shellwords.shellsplit(program) + [uri.path] case uri.scheme when "file" then argv when "ssh" then ssh_command(uri, argv) end end |
#recv_references ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/command/shared/remote_client.rb', line 37 def recv_references @remote_refs = {} @conn.recv_until(nil) do |line| oid, ref = REF_LINE.match(line).captures @remote_refs[ref] = oid.downcase unless oid == ZERO_OID end end |
#report_range_update(ref_names, old_oid, new_oid, is_ff) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/command/shared/remote_client.rb', line 59 def report_range_update(ref_names, old_oid, new_oid, is_ff) old_oid = repo.database.short_oid(old_oid) new_oid = repo.database.short_oid(new_oid) if is_ff revisions = "#{ old_oid }..#{ new_oid }" show_ref_update(" ", revisions, ref_names) else revisions = "#{ old_oid }...#{ new_oid }" show_ref_update("+", revisions, ref_names, "forced update") end end |
#report_ref_update(ref_names, error, old_oid = nil, new_oid = nil, is_ff = false) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/command/shared/remote_client.rb', line 46 def report_ref_update(ref_names, error, old_oid = nil, new_oid = nil, is_ff = false) return show_ref_update("!", "[rejected]", ref_names, error) if error return if old_oid == new_oid if old_oid == nil show_ref_update("*", "[new branch]", ref_names) elsif new_oid == nil show_ref_update("-", "[deleted]", ref_names) else report_range_update(ref_names, old_oid, new_oid, is_ff) end end |
#show_ref_update(flag, summary, ref_names, reason = nil) ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'lib/command/shared/remote_client.rb', line 72 def show_ref_update(flag, summary, ref_names, reason = nil) names = ref_names.compact.map { |name| repo.refs.short_name(name) } = " #{ flag } #{ summary } #{ names.join(" -> ") }" .concat(" (#{ reason })") if reason @stderr.puts end |
#ssh_command(uri, argv) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/command/shared/remote_client.rb', line 29 def ssh_command(uri, argv) ssh = ["ssh", uri.host] ssh += ["-p", uri.port.to_s] if uri.port ssh += ["-l", uri.user] if uri.user ssh + [Shellwords.shelljoin(argv)] end |
#start_agent(name, program, url, capabilities = []) ⇒ Object
13 14 15 16 17 |
# File 'lib/command/shared/remote_client.rb', line 13 def start_agent(name, program, url, capabilities = []) argv = build_agent_command(program, url) input, output, _ = Open3.popen2(Shellwords.shelljoin(argv)) @conn = Remotes::Protocol.new(name, output, input, capabilities) end |