Module: GitCliPrompt::Push

Includes:
CliPrompt, TR::CondUtils
Defined in:
lib/push.rb

Instance Method Summary collapse

Methods included from CliPrompt

#method_missing

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class GitCliPrompt::CliPrompt

Instance Method Details

#confirm_input(name, url) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/push.rb', line 69

def confirm_input(name, url)
 
  cont = []
  cont << ""
  cont << "  Name : #{name}"
  cont << "  URL  : #{url}"
  cont << ""

  pmt.yes?("  You've provided the following info. Proceed?\n#{cont.join("\r\n")}")

end

#confirm_push(name, url) ⇒ Object



49
50
51
52
53
# File 'lib/push.rb', line 49

def confirm_push(name, url)
  
  pmt.yes?("  Confirm push to repository '#{name}' [#{url}]?")

end

#prompt_new_remoteObject



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/push.rb', line 56

def prompt_new_remote
  
  name = pmt.ask("  Please provide a name of this remote config :", required: true)
  url = pmt.ask("  Please provide the URL:", required: true)

  if confirm_input(name, url)
    [name, url]
  else
    raise UserChangedMind
  end

end

#push(root, &block) ⇒ Object

Raises:

  • (PushError)


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/push.rb', line 7

def push(root, &block)

  raise PushError, "Root is empty" if is_empty?(root)

  begin

    ws = Gvcs::Workspace.new(root)

    raise PushError, "#{root} is not a workspace" if not ws.is_workspace?

    conf = ws.remote_config
    if is_empty?(conf)
      res = pmt.yes?("  There is no remote repository configured for workspace at '#{File.expand_path(root)}'. Do you want to add one?")
      raise UserAborted if not res 
      name, url = prompt_new_remote

      ws.add_remote(name, url)

      conf = ws.remote_config
    end

    branch = block.call(:push_to_branch) if block
    branch = ws.current_branch if is_empty?(branch)

    if conf.keys.length == 1
      # direct push
      name = conf.keys.first
      url = conf.values.first["push"]
      if confirm_push(name, url)
        ws.push_changes_with_tags(name, branch)
        block.call(:push_info, { name: name }) if block
      else
        raise UserAborted
      end
    else
      raise UserChangedMind
    end

  rescue TTY::Reader::InputInterrupt
  end
end