Module: Prick::Git

Defined in:
lib/prick/local/git.rb

Defined Under Namespace

Modules: Branch, Tag

Class Method Summary collapse

Class Method Details

.add(*files) ⇒ Object

Add files to the index



32
33
34
35
# File 'lib/prick/local/git.rb', line 32

def self.add(*files)
  files = Array(files).flatten
  Command.command "git add #{files.join(" ")}"
end

.added?(file = nil) ⇒ Boolean

True if the file was added to the index

Returns:

  • (Boolean)


38
39
40
41
# File 'lib/prick/local/git.rb', line 38

def self.added?(file = nil)
  re = file ? /^[ACDMR]. #{file}$/ : /^[ACDMR]/
  Command.command("git status --porcelain").any? { |l| l =~ re }
end

.branchObject

Access to branch methods



63
# File 'lib/prick/local/git.rb', line 63

def self.branch() Branch end

.clean?(file = nil) ⇒ Boolean

Return true if the repository has no modified files or unresolved conflicts. Requires the repository to have at least one commit

Returns:

  • (Boolean)


20
21
22
23
# File 'lib/prick/local/git.rb', line 20

def self.clean?(file = nil)
  re = file ? /^  #{file}(?: .*)?$/ : /^\?\?|!!/
  !Command.command("git status --porcelain").any? { |l| l !~ re }
end

.clone(url, directory = nil, branch: nil) ⇒ Object

Clone a repository



10
11
12
13
# File 'lib/prick/local/git.rb', line 10

def self.clone(url, directory = nil, branch: nil)
  branch_arg = branch ? "--branch #{branch}" : ""
  Command.command("git clone --quiet #{branch_arg} '#{url}' #{directory}")
end

.commit(msg) ⇒ Object

Commit changes on the current branch“



44
45
46
47
# File 'lib/prick/local/git.rb', line 44

def self.commit(msg)
  out = Command.command "git commit -m '#{msg}'", fail: false
  Command.status == 0 or raise Command.exception.exception(out.join("\n"))
end

.idObject

Return the current commit id



16
# File 'lib/prick/local/git.rb', line 16

def self.id() Command.command("git rev-parse HEAD").first end

.listObject

List files in repository



66
# File 'lib/prick/local/git.rb', line 66

def self.list() Command.command("git ls-files") end

.originObject

Return the origin of the repository



5
6
7
# File 'lib/prick/local/git.rb', line 5

def self.origin()
  Command.command("git remote get-url origin").first
end

.pullObject

Pull changes from repository



50
51
52
# File 'lib/prick/local/git.rb', line 50

def self.pull
  Command.command "git pull"
end

.pushObject

Push change to repository



55
56
57
# File 'lib/prick/local/git.rb', line 55

def self.push
  Command.command "git push --quiet --atomic"
end

.synchronized?Boolean

Return true if the repo is synchronized with the remote

Returns:

  • (Boolean)


26
27
28
29
# File 'lib/prick/local/git.rb', line 26

def self.synchronized?()
  out = Command.command "git rev-list --count --left-right 'HEAD...@{upstream}'"
  !(out.first =~ /^0\s+0$/).nil?
end

.tagObject

Access to tag methods



60
# File 'lib/prick/local/git.rb', line 60

def self.tag() Tag end