class Git
A static wrapper class for git
Public Class Methods
Retrieves the name of the current branch.
@return [String]
Current branch.
# File lib/git.rb, line 57 def self.current_branch `git branch`.rstrip end
Retrieves one commit message and filters it Todo: Armor this against code injection!
# File lib/git.rb, line 131 def self.get_filtered_message(commit, filter) `git log #{commit} -E --grep='#{filter}' --format=%b` end
Retrieves commit messages and filters them Todo: Armor this against code injection!
# File lib/git.rb, line 125 def self.get_filtered_messages(from_commit, to_commit, filter) `git log #{from_commit}..#{to_commit} -E --grep='#{filter}' --format=%b` end
Retrieves the first 99 lines of the annotation of a tag.
# File lib/git.rb, line 111 def self.get_tag_annotation(tag) test_tag tag `git tag --sort refname -l -n99 #{tag}`.rstrip end
Retrieves the author date of a tag
# File lib/git.rb, line 118 def self.get_tag_date(tag) test_tag tag `git log -1 --format=format:%ai #{tag}` end
Determines if the repository in the current directory is empty.
# File lib/git.rb, line 48 def self.is_empty_repository? `git show HEAD > /dev/null 2>&1` $? != 0 end
Determines whether the (current) directory is a git repository
@param [String] dir
Directory to check; if nil, uses the current directory.
@return [bool]
True if the directory is a Git repository, false if not.
# 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
Determines whether Git
is installed
@return [bool]
True if Git is installed, false if not.
# File lib/git.rb, line 24 def self.is_installed? begin `git --version` true rescue false end end
Launches the text editor that Git
uses for commit messages, and passes file as a command line argument to it.
@see github.com/git/git/blob/master/editor.c
Git's editor.c on GitHub
@param [String] file
Filename to pass to the editor.
@return [int]
Exit code of the editor process, or false if no editor found.
# 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
Private Class Methods
Tests if the given tag exists and fails if it doesn't
# File lib/git.rb, line 145 def self.test_tag(tag) fail "Invalid tag: #{tag}" unless tags.list.include?(tag) end