Module: Git

Extended by:
TtyIntegration
Defined in:
lib/Git/git.rb

Class Method Summary collapse

Methods included from TtyIntegration

bar, cmd, error, green, pastel, prompt, red, success, table, yellow

Class Method Details

.checkout(branch, options = :with_fetch) ⇒ Object



5
6
7
8
9
10
# File 'lib/Git/git.rb', line 5

def self.checkout(branch, options = :with_fetch)
  fetch(branch) if options == :with_fetch
  # prompt.say(pastel.yellow("[checkout] ") + pastel.green(branch))
  execute {"git checkout #{branch}"}
  self.pull branch  if options == :with_fetch
end

.delete_branch(branch) ⇒ Object



48
49
50
51
52
# File 'lib/Git/git.rb', line 48

def self.delete_branch branch
  # print "Delete branch: ".yellow
  # print "#{branch} \n\n".green
  execute {("git checkout develop && git branch -D #{branch}") }
end

.exist_branch?(branch) ⇒ Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/Git/git.rb', line 97

def self.exist_branch? branch
  execute {"git fetch origin #{branch}"}
end

.fetch(branch) ⇒ Object



84
85
86
87
88
# File 'lib/Git/git.rb', line 84

def self.fetch branch
  # prompt.say(pastel.yellow('[Fetch]: '))
  # prompt.say(pastel.yellow("origin/#{branch}\n\n"))
  execute { "git fetch origin #{branch}" }
end

.log_last_changes(branch) ⇒ Object



74
75
76
# File 'lib/Git/git.rb', line 74

def self.log_last_changes branch
  execute {%{git log origin/#{branch}..HEAD --oneline --format="%ad - %B}}
end

.merge(from, to) ⇒ Object



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
# File 'lib/Git/git.rb', line 12

def self.merge from, to
  # self.checkout(from)
  checkout(to, :local)
  # prompt.say(pastel.yellow('[Merge] '))
  # prompt.say(pastel.green("#{from} "))
  # prompt.say(pastel.yellow("into "))
  # prompt.say(pastel.green("#{to} \n\n"))
  result = cmd.run!("git pull origin #{from}")

  # processs, stderr , stdout= Open3.popen3("git pull origin #{from}") do |i, o, stderr, wait_thr|
  #   [wait_thr.value, stderr.read, o.read] 
  # end
  if result.success?
    return result.out
  else
    print "Conflicts on merge!".yellow.bg_red
    print "\n\nResolve conflicts and commit. \n"
    print "After type '1' for to continue or '0' for abort\n".yellow
    choice = STDIN.gets.chomp
    print "\n#{choice}, "
    print "ok!\n".green

    case choice
    when '1'
      print "Continuing...\n\n"
    else
      print "Aborting merge...\n\n"
      execute { ('git merge --abort') }
      raise 'Aborting...'
    end

  end

  # execute {"git pull origin #{from}"}
end

.new_branch(branch) ⇒ Object



90
91
92
93
94
# File 'lib/Git/git.rb', line 90

def self.new_branch branch
  # prompt.say(pastel.yellow('Create new branch: '))
  # prompt.say(pastel.green( "#{branch}\n"))
  execute {  "git checkout -b #{branch}" }
end

.pull(branch) ⇒ Object



78
79
80
81
82
# File 'lib/Git/git.rb', line 78

def self.pull branch
  # prompt.say(pastel.yellow('[Pull]: '))
  # prompt.say(pastel.yellow("#{branch}\n\n"))
  execute { "git pull origin #{branch}" }
end

.push(branch) ⇒ Object



62
63
64
65
66
# File 'lib/Git/git.rb', line 62

def self.push branch
  # prompt.say(pastel.yellow('[Push]: '))
  # prompt.say(pastel.green("#{branch}\n\n"))
  execute {"git push origin #{branch}"}
end

.push_force(branch) ⇒ Object



68
69
70
71
72
# File 'lib/Git/git.rb', line 68

def self.push_force branch
  # print "Push --force: ".yellow
  # print "#{branch}\n\n".green
  execute {"git push origin #{branch} -f"}
end

.reset_hard(from, to) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/Git/git.rb', line 54

def self.reset_hard from, to
  self.fetch from
  self.checkout(to)
  # print "Reset --hard:  #{to} is equal: ".yellow
  # print "origin/#{from}\n".green
  execute { "git reset --hard origin/#{from}\n\n" }
end