Module: GitHelpersMixin

Included in:
Init, RecreateBranch, Repository, ShareReReRe::PullReReRe, ShareReReRe::PushReReRe
Defined in:
lib/git_bpf/lib/git-helpers.rb

Instance Method Summary collapse

Instance Method Details

#branchExists?(branch) ⇒ Boolean

Returns:

  • (Boolean)


86
87
88
89
90
91
92
93
94
# File 'lib/git_bpf/lib/git-helpers.rb', line 86

def branchExists?(branch)
  ref = (branch.include? "refs/heads/") ? branch : "refs/heads/#{branch}"
  begin
    git('show-ref', '--verify', '--quiet', ref)
  rescue
    return false
  end
  return true
end

#context(work_tree, git_dir, *args) ⇒ Object



76
77
78
79
80
81
82
83
84
# File 'lib/git_bpf/lib/git-helpers.rb', line 76

def context(work_tree, git_dir, *args)
  # Git pull requires absolute paths when executed from outside of the
  # repository's work tree.
  params = [
    "--git-dir=#{File.expand_path(git_dir)}",
    "--work-tree=#{File.expand_path(work_tree)}"
  ]
  return params + args
end

#promptYN(message) ⇒ Object



110
111
112
113
114
115
116
117
# File 'lib/git_bpf/lib/git-helpers.rb', line 110

def promptYN(message)
  puts
  puts "#{message} [y/N]"
  unless STDIN.gets.chomp == 'y'
    return false
  end
  return true
end

#refExists?(ref) ⇒ Boolean

Returns:

  • (Boolean)


96
97
98
99
100
101
102
103
# File 'lib/git_bpf/lib/git-helpers.rb', line 96

def refExists?(ref)
  begin
    git('show-ref', '--tags', '--heads', ref)
  rescue
    return false
  end
  return true
end

#terminate(message = nil) ⇒ Object



105
106
107
108
# File 'lib/git_bpf/lib/git-helpers.rb', line 105

def terminate(message = nil)
  puts message if message != nil
  throw :exit
end