Class: FlatHash::Git
- Inherits:
-
Vcs
show all
- Defined in:
- lib/flat_hash/git.rb
Instance Method Summary
collapse
Methods inherited from Vcs
#commit, #execute, #init, #sh
Instance Method Details
#addremovecommit(comment) ⇒ Object
14
15
16
17
18
|
# File 'lib/flat_hash/git.rb', line 14
def addremovecommit
execute "add -A"
execute "ls-files --deleted -z | xargs -0 git rm"
commit
end
|
#changeset(id) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/flat_hash/git.rb', line 27
def changeset id
change = FlatHash::Changeset.new
commit = git.commit(id)
change.id = commit.sha
change.time = commit.date
change.author = commit.author.to_s
all_changes = execute("show --pretty=\"format:\" --name-only #{commit}")
all_changes.shift
change.additions = commit.diffs.select {|diff| diff.new_file}.map {|diff| diff.a_path }.uniq
change.deletions = []
change.modifications = []
all_changes.each do |path|
if commit_contains(commit,path)
change.modifications << path
else
change.deletions << path
end
end
change.modifications = change.modifications - change.additions
change.description = commit.message
change
end
|
#changesets(path = '.') ⇒ Object
20
21
22
23
24
25
|
# File 'lib/flat_hash/git.rb', line 20
def changesets path='.'
sh("git log --format=%H -- #{path}") do |status, lines|
raise "failed with status #{status}:\n#{lines.join("\n")}" unless status.exitstatus == 128
[]
end
end
|
#contains?(id, path) ⇒ Boolean
60
61
62
|
# File 'lib/flat_hash/git.rb', line 60
def contains? id, path
commit_contains git.commit(id), path
end
|
#content_at(path, commit) ⇒ Object
50
51
52
|
# File 'lib/flat_hash/git.rb', line 50
def content_at path, commit
execute("show #{commit}:#{path}").join("\n")
end
|
#files_at(commit, path = nil) ⇒ Object
54
55
56
57
58
|
# File 'lib/flat_hash/git.rb', line 54
def files_at commit, path=nil
tree = git.commit(commit).tree
tree = tree/path if path
tree ? tree.blobs.map {|blob| path ? "#{path}/#{blob.name}" : blob.name } : []
end
|
6
7
8
|
# File 'lib/flat_hash/git.rb', line 6
def git
@git ||= Grit::Repo.new('.')
end
|
10
11
12
|
# File 'lib/flat_hash/git.rb', line 10
def name
:git
end
|