Class: Git
- Inherits:
-
Object
- Object
- Git
- Defined in:
- lib/git.rb
Overview
A static wrapper class for git
Constant Summary collapse
nil
Class Method Summary collapse
-
.current_branch ⇒ String
Retrieves the name of the current branch.
-
.get_filtered_message(commit, filter) ⇒ Object
Retrieves one commit message and filters it Todo: Armor this against code injection!.
-
.get_filtered_messages(from_commit, to_commit, filter) ⇒ Object
Retrieves commit messages and filters them Todo: Armor this against code injection!.
-
.get_tag_annotation(tag) ⇒ Object
Retrieves the first 99 lines of the annotation of a tag.
-
.get_tag_date(tag) ⇒ Object
Retrieves the author date of a tag.
-
.is_empty_repository? ⇒ Boolean
Determines if the repository in the current directory is empty.
-
.is_git_repository?(dir = nil) ⇒ bool
Determines whether the (current) directory is a git repository.
-
.is_installed? ⇒ bool
Determines whether Git is installed.
-
.launch_editor(file) ⇒ int
Launches the text editor that Git uses for commit messages, and passes file as a command line argument to it.
Class Method Details
.current_branch ⇒ String
Retrieves the name of the current branch.
57 58 59 |
# File 'lib/git.rb', line 57 def self.current_branch `git branch`.rstrip end |
.get_filtered_message(commit, filter) ⇒ Object
Retrieves one commit message and filters it Todo: Armor this against code injection!
131 132 133 |
# File 'lib/git.rb', line 131 def self.(commit, filter) `git log #{commit} -E --grep='#{filter}' --format=%b` end |
.get_filtered_messages(from_commit, to_commit, filter) ⇒ Object
Retrieves commit messages and filters them Todo: Armor this against code injection!
125 126 127 |
# File 'lib/git.rb', line 125 def self.(from_commit, to_commit, filter) `git log #{from_commit}..#{to_commit} -E --grep='#{filter}' --format=%b` end |
.get_tag_annotation(tag) ⇒ Object
Retrieves the first 99 lines of the annotation of a tag.
111 112 113 114 |
# File 'lib/git.rb', line 111 def self.get_tag_annotation(tag) test_tag tag `git tag --sort refname -l -n99 #{tag}`.rstrip end |
.get_tag_date(tag) ⇒ Object
Retrieves the author date of a tag
118 119 120 121 |
# File 'lib/git.rb', line 118 def self.get_tag_date(tag) test_tag tag `git log -1 --format=format:%ai #{tag}` end |
.is_empty_repository? ⇒ Boolean
Determines if the repository in the current directory is empty.
48 49 50 51 |
# File 'lib/git.rb', line 48 def self.is_empty_repository? `git show HEAD > /dev/null 2>&1` $? != 0 end |
.is_git_repository?(dir = nil) ⇒ bool
Determines whether the (current) directory is a git repository
40 41 42 43 44 |
# File 'lib/git.rb', line 40 def self.is_git_repository?(dir = nil) dir = Dir.pwd if dir.nil? system("git status > /dev/null 2>&1") $? == 0 end |
.is_installed? ⇒ bool
Determines whether Git is installed
24 25 26 27 28 29 30 31 |
# File 'lib/git.rb', line 24 def self.is_installed? begin `git --version` true rescue false end end |
.launch_editor(file) ⇒ int
Launches the text editor that Git uses for commit messages, and passes file as a command line argument to it.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/git.rb', line 73 def self.launch_editor(file) # const char *editor = getenv("GIT_EDITOR"); editor = ENV['GIT_EDITOR'] # const char *terminal = getenv("TERM"); terminal = ENV['TERM']; # int terminal_is_dumb = !terminal || !strcmp(terminal, "dumb"); terminal_is_dumb = !terminal || terminal == 'dumb' # if (!editor && editor_program) editor = `git config --get core.editor`.rstrip if editor.nil? || editor.empty? # if (!editor && !terminal_is_dumb) # editor = getenv("VISUAL"); editor = ENV['VISUAL'] if (editor.nil? || editor.empty?) && !terminal_is_dumb # if (!editor) # editor = getenv("EDITOR"); editor = ENV['EDITOR'] if (editor.nil? || editor.empty?) # if (!editor && terminal_is_dumb) # return NULL; # if (!editor) # editor = DEFAULT_EDITOR; # Use vi, Git's hard-coded default editor = 'vi' if (editor.nil? || editor.empty?) && !terminal_is_dumb if editor && !editor.empty? system "#{editor} '#{file}'" $? else false end end |