Class: Pj::Git
- Inherits:
-
Object
- Object
- Pj::Git
- Defined in:
- lib/pj/git.rb
Instance Method Summary collapse
- #check_commit ⇒ Object
- #commit(msg) ⇒ Object
- #git(cmd) ⇒ Object
-
#initialize(repo_name) ⇒ Git
constructor
A new instance of Git.
- #needs_commit? ⇒ Boolean
- #origin? ⇒ Boolean
- #push(remote, branch) ⇒ Object
- #status ⇒ Object
- #status_short ⇒ Object
- #upstream? ⇒ Boolean
Constructor Details
#initialize(repo_name) ⇒ Git
5 6 7 |
# File 'lib/pj/git.rb', line 5 def initialize(repo_name) @repo = Pj::Config.repo_dir(repo_name) end |
Instance Method Details
#check_commit ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/pj/git.rb', line 23 def check_commit return unless needs_commit? puts status_short puts "you have to commit the above changes first" puts "enter commit message:" msg = STDIN.gets.chomp commit msg end |
#commit(msg) ⇒ Object
32 33 34 35 |
# File 'lib/pj/git.rb', line 32 def commit(msg) git "add --all" git "commit --all --message=\"#{msg}\"" end |
#git(cmd) ⇒ Object
49 50 51 |
# File 'lib/pj/git.rb', line 49 def git(cmd) Dir.chdir(@repo) { `git #{cmd}` } end |
#needs_commit? ⇒ Boolean
9 10 11 |
# File 'lib/pj/git.rb', line 9 def needs_commit? status_short.empty? ? false : true end |
#origin? ⇒ Boolean
18 19 20 21 |
# File 'lib/pj/git.rb', line 18 def origin? msg = git "remote --verbose" msg.include? "origin" end |
#push(remote, branch) ⇒ Object
45 46 47 |
# File 'lib/pj/git.rb', line 45 def push(remote, branch) git "push #{remote} #{branch}" end |
#status ⇒ Object
37 38 39 |
# File 'lib/pj/git.rb', line 37 def status git "status" end |
#status_short ⇒ Object
41 42 43 |
# File 'lib/pj/git.rb', line 41 def status_short git "status --short" end |
#upstream? ⇒ Boolean
13 14 15 16 |
# File 'lib/pj/git.rb', line 13 def upstream? msg = git "remote --verbose" msg.include? "upstream" end |