Module: Bard::CLI::Git

Defined in:
lib/bard/git.rb

Class Method Summary collapse

Class Method Details

.current_branchObject



4
5
6
7
8
# File 'lib/bard/git.rb', line 4

def current_branch
  ref = `git symbolic-ref HEAD 2>&1`.chomp
  return false if ref =~ /^fatal:/
  ref.sub(/refs\/heads\//, '') # refs/heads/master ... we want "master"
end

.current_shaObject



10
11
12
# File 'lib/bard/git.rb', line 10

def current_sha
  sha_of("HEAD")
end

.fast_forward_merge?(root, branch) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
# File 'lib/bard/git.rb', line 14

def fast_forward_merge?(root, branch)
  root_head = sha_of(root)
  branch_head = sha_of(branch)
  common_ancestor = `git merge-base #{root_head} #{branch_head}`.chomp
  common_ancestor == root_head
end

.sha_of(ref) ⇒ Object



25
26
27
# File 'lib/bard/git.rb', line 25

def sha_of ref
  `git rev-parse #{ref}`.chomp
end

.up_to_date_with_remote?(branch) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/bard/git.rb', line 21

def up_to_date_with_remote? branch
  sha_of(branch) == sha_of("origin/#{branch}")
end