Top Level Namespace

Defined Under Namespace

Modules: Mamiya

Instance Method Summary collapse

Instance Method Details

#git_headObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/mamiya/helpers/git.rb', line 27

def git_head
  git_show = `git show --pretty=fuller -s`
  commit, comment = git_show.split(/\n\n/, 2)

  {
    commit: commit.match(/^commit (.+)$/)[1],
    author: commit.match(/^Author:\s*(?<name>.+?) <(?<email>.+?)>$/).
      tap {|match| break Hash[match.names.map {|name| [name.to_sym, match[name]] }] },
    author_date: Time.parse(commit.match(/^AuthorDate:\s*(.+)$/)[1]),
    committer: commit.match(/^Commit:\s*(?<name>.+?) <(?<email>.+?)>$/).
      tap {|match| break Hash[match.names.map {|name| [name.to_sym, match[name]] }] },
    commit_date: Time.parse(commit.match(/^CommitDate:\s*(.+)$/)[1]),
  }
end

#git_ignored_filesObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/mamiya/helpers/git.rb', line 10

def git_ignored_files
  git_clean_out = `git clean -ndx`.lines
  prefix = /^Would (?:remove|skip repository) /

  if git_clean_out.any? { |_| prefix !~ _ }
    puts git_clean_out
    raise "`git clean -ndx` doesn't return line starting with 'Would remove' or 'Would skip'"
  end

  excludes = git_clean_out.grep(prefix).map{ |_| _.sub(prefix, '').chomp }
  if package_under
    excludes.grep(/^#{Regexp.escape(package_under)}/).map{ |_| _.sub(/^#{Regexp.escape(package_under)}\/?/, '') }
  else
    excludes
  end
end

#git_managed?Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/mamiya/helpers/git.rb', line 6

def git_managed?
  system *%w(git rev-parse --git-dir), err: File::NULL, out: File::NULL
end