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, remote = nil) ⇒ Boolean

Returns:

  • (Boolean)


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

def branchExists?(branch, remote = nil)
  if remote
    ref = "refs/remotes/#{remote}/#{branch}"
  else
    ref = (branch.include? "refs/heads/") ? branch : "refs/heads/#{branch}"
  end
  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



114
115
116
117
118
119
120
121
# File 'lib/git_bpf/lib/git-helpers.rb', line 114

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

#refExists?(ref) ⇒ Boolean

Returns:

  • (Boolean)


100
101
102
103
104
105
106
107
# File 'lib/git_bpf/lib/git-helpers.rb', line 100

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

#terminate(message = nil) ⇒ Object



109
110
111
112
# File 'lib/git_bpf/lib/git-helpers.rb', line 109

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