Module: Git::Modified

Includes:
Contracts, Contracts::Modules
Defined in:
lib/git/modified.rb,
lib/git/modified/version.rb

Constant Summary collapse

VERSION =
"0.2.0"

Class Method Summary collapse

Class Method Details

.latest_hashObject



50
51
52
# File 'lib/git/modified.rb', line 50

def self.latest_hash
  `git log --pretty=format:'%h' -n 1`
end

.modified(hash = nil) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/git/modified.rb', line 25

def self.modified(hash = nil)
  if hash.nil?
    show_modified_files_on_working_tree
  else
    show_modified_files_on_commit hash
  end
end

.runObject



10
11
12
13
14
15
16
17
# File 'lib/git/modified.rb', line 10

def self.run
  case ARGV.first
  when '-v', '--version'
    version
  else
    modified ARGV.first
  end
end

.show_modified_files_on_commit(hash) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/git/modified.rb', line 39

def self.show_modified_files_on_commit(hash)
  hashes = `git show --summary --format="%P" #{hash} | head -n 1`.split ' '

  if hashes.size == 2
    puts `git diff --name-only #{hashes[0]}...#{hashes[1]}`
  else
    puts `git log -m -1 --name-only --pretty="format:" #{hash}`
  end
end

.show_modified_files_on_working_treeObject



34
35
36
# File 'lib/git/modified.rb', line 34

def self.show_modified_files_on_working_tree
  puts `git status --porcelain`.each_line.map { |x| x[3..-1] }
end

.versionObject



20
21
22
# File 'lib/git/modified.rb', line 20

def self.version
  puts Git::Modified::VERSION
end