class Git::Git

Public Class Methods

current_branch() click to toggle source

Retrieves the name of the current branch.

@return [String]

Current branch.
# File lib/tag_changelog/git/git.rb, line 54
def self.current_branch
  `git name-rev --name-only HEAD`.strip
end
get_filtered_message(commit, filter) click to toggle source

Retrieves one commit message and filters it Todo: Armor this against code injection!

# File lib/tag_changelog/git/git.rb, line 132
def self.get_filtered_message(commit, filter)
  `git log #{commit} -E --grep='#{filter}' --format=%b`
end
get_filtered_messages(from_commit, to_commit, filter = nil) click to toggle source

Retrieves commit messages and filters them Todo: Armor this against code injection!

# File lib/tag_changelog/git/git.rb, line 122
def self.get_filtered_messages(from_commit, to_commit, filter = nil)
  if filter
    `git log #{from_commit}..#{to_commit} -E --grep='#{filter}' --format=%b`
  else
    `git log #{from_commit}..#{to_commit} --oneline`
  end
end
get_tag_annotation(tag) click to toggle source

Retrieves the first 99 lines of the annotation of a tag.

# File lib/tag_changelog/git/git.rb, line 108
def self.get_tag_annotation(tag)
  test_tag tag
  `git tag --sort refname -l -n99 #{tag}`.rstrip
end
get_tag_date(tag) click to toggle source

Retrieves the author date of a tag

# File lib/tag_changelog/git/git.rb, line 115
def self.get_tag_date(tag)
  test_tag tag
  `git log -1 --format=format:%ai #{tag}`
end
is_empty_repository?() click to toggle source

Determines if the repository in the current directory is empty.

# File lib/tag_changelog/git/git.rb, line 45
def self.is_empty_repository?
  `git show HEAD > /dev/null 2>&1`
  $? != 0
end
is_git_repository?(dir = nil) click to toggle source

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/tag_changelog/git/git.rb, line 37
def self.is_git_repository?(dir = nil)
  dir = Dir.pwd if dir.nil?
  system("git status > /dev/null 2>&1")
  $? == 0
end
is_installed?() click to toggle source

Determines whether Git is installed

@return [bool]

True if Git is installed, false if not.
# File lib/tag_changelog/git/git.rb, line 25
def self.is_installed?
  `git --version`
  $? == 0
end
launch_editor(file) click to toggle source

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/tag_changelog/git/git.rb, line 70
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

tags() click to toggle source

Ensures lazy loading of the tag list to enable calling code to change the working directory first.

# File lib/tag_changelog/git/git.rb, line 140
def self.tags
  @@tags = TagList.new unless @@tags
  @@tags
end
test_tag(tag) click to toggle source

Tests if the given tag exists and fails if it doesn't

# File lib/tag_changelog/git/git.rb, line 146
def self.test_tag(tag)
  fail "Invalid tag: #{tag}" unless tags.list.include?(tag)
end