Module: Perfer::Git
- Defined in:
- lib/perfer/git.rb
Class Method Summary collapse
- .current_branch ⇒ Object
- .current_commit ⇒ Object
- .git(command) ⇒ Object
- .goto_commit(commit) ⇒ Object
- .repository? ⇒ Boolean
- .working_directory_clean? ⇒ Boolean
Class Method Details
.current_branch ⇒ Object
16 17 18 19 20 |
# File 'lib/perfer/git.rb', line 16 def current_branch branch = git 'symbolic-ref --quiet HEAD' branch = branch[/[^\/]+$/] if branch branch end |
.current_commit ⇒ Object
22 23 24 |
# File 'lib/perfer/git.rb', line 22 def current_commit git 'rev-parse --quiet --verify HEAD' end |
.git(command) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/perfer/git.rb', line 4 def git(command) output = `git #{command}` output.chomp! return nil if output.empty? return false if $?.exitstatus != 0 output end |
.goto_commit(commit) ⇒ Object
30 31 32 33 |
# File 'lib/perfer/git.rb', line 30 def goto_commit(commit) raise Error, Errors::WORKING_DIR_DIRTY unless working_directory_clean? git "reset --quiet --hard #{commit}" end |
.repository? ⇒ Boolean
12 13 14 |
# File 'lib/perfer/git.rb', line 12 def repository? git "rev-parse --git-dir 2>#{File::NULL}" end |
.working_directory_clean? ⇒ Boolean
26 27 28 |
# File 'lib/perfer/git.rb', line 26 def working_directory_clean? git('status --porcelain --untracked-files=no') == nil end |