Module: Braid::Operations::Git

Included in:
Command, Braid::Operations
Defined in:
lib/braid/operations.rb

Instance Method Summary collapse

Instance Method Details

#git_checkout(treeish) ⇒ Object



23
24
25
26
27
28
# File 'lib/braid/operations.rb', line 23

def git_checkout(treeish)
  # TODO debug
  msg "Checking out '#{treeish}'."
  exec!("git checkout #{treeish}")
  true
end

#git_commit(message) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/braid/operations.rb', line 4

def git_commit(message)
  status, out, err = exec("git commit -m #{message.inspect} --no-verify")

  if status == 0
    true
  elsif out.match(/nothing.* to commit/)
    false
  else
    raise Braid::Commands::ShellExecutionError, err
  end
end

#git_fetch(remote) ⇒ Object



16
17
18
19
20
21
# File 'lib/braid/operations.rb', line 16

def git_fetch(remote)
  # open4 messes with the pipes of index-pack
  system("git fetch -n #{remote} 2>&1 > /dev/null")
  raise Braid::Commands::ShellExecutionError unless $? == 0
  true
end

#git_merge_base(target, source) ⇒ Object

Returns the base commit or nil.



31
32
33
34
35
36
# File 'lib/braid/operations.rb', line 31

def git_merge_base(target, source)
  status, out, err = exec!("git merge-base #{target} #{source}")
  out.strip
rescue Braid::Commands::ShellExecutionError
  nil
end

#git_merge_ours(commit) ⇒ Object

Implies no commit.



55
56
57
58
# File 'lib/braid/operations.rb', line 55

def git_merge_ours(commit)
  exec!("git merge -s ours --no-commit #{commit}")
  true
end

#git_merge_subtree(commit) ⇒ Object

Implies no commit.



61
62
63
64
65
# File 'lib/braid/operations.rb', line 61

def git_merge_subtree(commit)
  # TODO which options are needed?
  exec!("git merge -s subtree --no-commit --no-ff #{commit}")
  true
end

#git_read_tree(treeish, prefix) ⇒ Object



67
68
69
70
# File 'lib/braid/operations.rb', line 67

def git_read_tree(treeish, prefix)
  exec!("git read-tree --prefix=#{prefix}/ -u #{treeish}")
  true
end

#git_remote_add(remote, path, branch) ⇒ Object

Implies tracking.



44
45
46
47
# File 'lib/braid/operations.rb', line 44

def git_remote_add(remote, path, branch)
  exec!("git remote add -t #{branch} -m #{branch} #{remote} #{path}")
  true
end

#git_reset_hard(target) ⇒ Object



49
50
51
52
# File 'lib/braid/operations.rb', line 49

def git_reset_hard(target)
  exec!("git reset --hard #{target}")
  true
end

#git_rev_parse(commit) ⇒ Object



38
39
40
41
# File 'lib/braid/operations.rb', line 38

def git_rev_parse(commit)
  status, out, err = exec!("git rev-parse #{commit}")
  out.strip
end

#git_rm_r(path) ⇒ Object



72
73
74
75
# File 'lib/braid/operations.rb', line 72

def git_rm_r(path)
  exec!("git rm -r #{path}")
  true
end

#local_changes?Boolean

Returns:

  • (Boolean)


77
78
79
80
# File 'lib/braid/operations.rb', line 77

def local_changes?
  status, out, err = exec("git status")
  out.split("\n").grep(/nothing to commit \(working directory clean\)/).empty?
end