Module: Prick::Git
- Defined in:
- lib/prick/local/git.rb
Defined Under Namespace
Class Method Summary collapse
-
.add(*files) ⇒ Object
Add files to the index.
-
.added?(file = nil) ⇒ Boolean
True if the file was added to the index.
-
.branch ⇒ Object
Access to branch methods.
-
.clean?(file = nil) ⇒ Boolean
Return true if the repository has no modified files or unresolved conflicts.
-
.clone(url, directory = nil, branch: nil) ⇒ Object
Clone a repository.
-
.commit(msg) ⇒ Object
Commit changes on the current branch“.
-
.id ⇒ Object
Return the current commit id.
-
.list ⇒ Object
List files in repository.
-
.origin ⇒ Object
Return the origin of the repository.
-
.pull ⇒ Object
Pull changes from repository.
-
.push ⇒ Object
Push change to repository.
-
.synchronized? ⇒ Boolean
Return true if the repo is synchronized with the remote.
-
.tag ⇒ Object
Access to tag methods.
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
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 |
.branch ⇒ Object
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
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 |
.id ⇒ Object
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 |
.list ⇒ Object
List files in repository
66 |
# File 'lib/prick/local/git.rb', line 66 def self.list() Command.command("git ls-files") end |
.origin ⇒ Object
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 |
.pull ⇒ Object
Pull changes from repository
50 51 52 |
# File 'lib/prick/local/git.rb', line 50 def self.pull Command.command "git pull" end |
.push ⇒ Object
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
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 |
.tag ⇒ Object
Access to tag methods
60 |
# File 'lib/prick/local/git.rb', line 60 def self.tag() Tag end |