Class: Flux::Git::Branch

Inherits:
Struct
  • Object
show all
Defined in:
lib/flux/git.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo_path, remote, name) ⇒ Branch

Returns a new instance of Branch.



50
51
52
53
54
55
# File 'lib/flux/git.rb', line 50

def initialize(repo_path, remote, name)
  super

  @git  = Git.git(repo_path)
  @repo = Git.repo(repo_path)
end

Instance Attribute Details

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



37
38
39
# File 'lib/flux/git.rb', line 37

def name
  @name
end

#remoteObject

Returns the value of attribute remote

Returns:

  • (Object)

    the current value of remote



37
38
39
# File 'lib/flux/git.rb', line 37

def remote
  @remote
end

#repo_pathObject

Returns the value of attribute repo_path

Returns:

  • (Object)

    the current value of repo_path



37
38
39
# File 'lib/flux/git.rb', line 37

def repo_path
  @repo_path
end

Class Method Details

.current(repo_path = Git.repo_path) ⇒ Object



38
39
40
# File 'lib/flux/git.rb', line 38

def self.current(repo_path = Git.repo_path)
  Branch.local(Git.repo(repo_path).head.name, repo_path)
end

.local(name, repo_path = Git.repo_path) ⇒ Object



46
47
48
# File 'lib/flux/git.rb', line 46

def self.local(name, repo_path = Git.repo_path)
  new(repo_path, nil, name)
end

.remote(name, remote = 'origin', repo_path = Git.repo_path) ⇒ Object



42
43
44
# File 'lib/flux/git.rb', line 42

def self.remote(name, remote = 'origin', repo_path = Git.repo_path)
  new(repo_path, remote, name)
end

Instance Method Details

#checkoutObject



71
72
73
# File 'lib/flux/git.rb', line 71

def checkout
  tap { @git.checkout({}, @name) }
end

#config(var, value = nil) ⇒ Object



57
58
59
60
61
62
63
64
65
# File 'lib/flux/git.rb', line 57

def config(var, value = nil)
  gitvar = "branch.#{name}.#{var.gsub('_', '')}"

  if value
    @git.config({:add => true}, gitvar, value)
  else
    @git.config({}, gitvar).chomp
  end
end

#create(parent) ⇒ Object



67
68
69
# File 'lib/flux/git.rb', line 67

def create(parent)
  tap { @git.branch({}, @name, parent.name) }
end

#fqdnObject



75
76
77
# File 'lib/flux/git.rb', line 75

def fqdn
  remote ? "#{remote}/#{name}" : name
end

#include?(branch) ⇒ Boolean Also known as: includes?

Returns:

  • (Boolean)


79
80
81
# File 'lib/flux/git.rb', line 79

def include?(branch)
  @repo.commits_between(fqdn, branch.fqdn).empty?
end

#publish(upstream) ⇒ Object



89
90
91
92
93
# File 'lib/flux/git.rb', line 89

def publish(upstream)
  tap {
    @git.push({}, upstream.remote, "+#{@name}:#{upstream.name}")
  }
end

#synced?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/flux/git.rb', line 99

def synced?
  upstream.top.sha == top.sha
end

#topObject



85
86
87
# File 'lib/flux/git.rb', line 85

def top
  @repo.commits(fqdn, 1).first
end

#track(upstream) ⇒ Object



95
96
97
# File 'lib/flux/git.rb', line 95

def track(upstream)
  tap { @git.branch({:set_upstream => true}, @name, upstream.fqdn) }
end

#upstreamObject



103
104
105
106
107
108
# File 'lib/flux/git.rb', line 103

def upstream
  remote = config('remote')
  name   = config('merge').sub('refs/heads/', '')

  Branch.remote(name, remote, repo_path)
end