Commit 61d74bb7ab2dfd64998d7a0b1cff16ff8043ff51

Added support for git to Ohcount

Commit diff

lib/ohcount/git_file_context.rb

 
1
2module Ohcount
3
4class GitFileContext
5 attr_reader :filename, :branch, :git_dir, :file_location
6 attr_accessor :filenames
7
8 def initialize(git_dir, filename, filenames = [], branch = "HEAD")
9 @git_dir = git_dir
10 @branch = branch
11 @filenames = filenames
12 @filename = filename
13 @file_location = @filename
14 end
15
16 def filenames
17 if @filenames.empty?
18 @filenames = `git --git-dir=#{@git_dir} ls-tree -r --name-only --full-name #{@branch}`.split('\n')
19 end
20 @filenames
21 end
22
23 def contents
24 @cached_contents ||= `git --git-dir=#{@git_dir} show #{@branch}:#{@filename}`
25 end
26end
27
28end
toggle raw diff