grit 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of grit might be problematic. Click here for more details.
- data/History.txt +4 -0
- data/Rakefile +1 -1
- data/grit.gemspec +2 -2
- data/lib/grit.rb +1 -1
- data/lib/grit/index.rb +69 -27
- data/lib/grit/status.rb +2 -0
- metadata +2 -2
data/History.txt
CHANGED
data/Rakefile
CHANGED
@@ -98,7 +98,7 @@ task :release => :build do
|
|
98
98
|
sh "git commit --allow-empty -a -m 'Release #{version}'"
|
99
99
|
sh "git tag v#{version}"
|
100
100
|
sh "git push origin master"
|
101
|
-
sh "git push v#{version}"
|
101
|
+
sh "git push origin v#{version}"
|
102
102
|
sh "gem push pkg/#{name}-#{version}.gem"
|
103
103
|
end
|
104
104
|
|
data/grit.gemspec
CHANGED
data/lib/grit.rb
CHANGED
data/lib/grit/index.rb
CHANGED
@@ -1,21 +1,36 @@
|
|
1
1
|
module Grit
|
2
2
|
|
3
3
|
class Index
|
4
|
-
|
4
|
+
# Public: Gets/Sets the Grit::Repo to which this index belongs.
|
5
|
+
attr_accessor :repo
|
5
6
|
|
7
|
+
# Public: Gets/Sets the Hash tree map that holds the changes to be made
|
8
|
+
# in the next commit.
|
9
|
+
attr_accessor :tree
|
10
|
+
|
11
|
+
# Public: Gets/Sets the Grit::Tree object representing the tree upon
|
12
|
+
# which the next commit will be based.
|
13
|
+
attr_accessor :current_tree
|
14
|
+
|
15
|
+
# Initialize a new Index object.
|
16
|
+
#
|
17
|
+
# repo - The Grit::Repo to which the index belongs.
|
18
|
+
#
|
19
|
+
# Returns the newly initialized Grit::Index.
|
6
20
|
def initialize(repo)
|
7
21
|
self.repo = repo
|
8
22
|
self.tree = {}
|
9
23
|
self.current_tree = nil
|
10
24
|
end
|
11
25
|
|
12
|
-
# Add a file to the index
|
13
|
-
# +path+ is the path (including filename)
|
14
|
-
# +data+ is the binary contents of the file
|
26
|
+
# Public: Add a file to the index.
|
15
27
|
#
|
16
|
-
#
|
17
|
-
|
18
|
-
|
28
|
+
# path - The String file path including filename (no slash prefix).
|
29
|
+
# data - The String binary contents of the file.
|
30
|
+
#
|
31
|
+
# Returns nothing.
|
32
|
+
def add(path, data)
|
33
|
+
path = path.split('/')
|
19
34
|
filename = path.pop
|
20
35
|
|
21
36
|
current = self.tree
|
@@ -29,31 +44,49 @@ module Grit
|
|
29
44
|
current[filename] = data
|
30
45
|
end
|
31
46
|
|
32
|
-
#
|
33
|
-
#
|
47
|
+
# Public: Delete the given file from the index.
|
48
|
+
#
|
49
|
+
# path - The String file path including filename (no slash prefix).
|
50
|
+
#
|
51
|
+
# Returns nothing.
|
52
|
+
def delete(path)
|
53
|
+
add(path, false)
|
54
|
+
end
|
55
|
+
|
56
|
+
# Public: Read the contents of the given Tree into the index to use as a
|
57
|
+
# starting point for the index.
|
58
|
+
#
|
59
|
+
# tree - The String branch/tag/sha of the Git tree object.
|
34
60
|
#
|
35
|
-
# Returns
|
61
|
+
# Returns nothing.
|
36
62
|
def read_tree(tree)
|
37
63
|
self.current_tree = self.repo.tree(tree)
|
38
64
|
end
|
39
65
|
|
40
|
-
# Commit the contents of the index
|
41
|
-
# +message+ is the commit message [nil]
|
42
|
-
# +parents+ is one or more commits to attach this commit to to form a new head [nil]
|
43
|
-
# +actor+ is the details of the user making the commit [nil]
|
44
|
-
# +last_tree+ is a tree to compare with - to avoid making empty commits [nil]
|
45
|
-
# +head+ is the branch to write this head to [master]
|
66
|
+
# Public: Commit the contents of the index
|
46
67
|
#
|
47
|
-
#
|
48
|
-
|
68
|
+
# message - The String commit message.
|
69
|
+
# parents - Array of String commit SHA1s or Grit::Commit objects to
|
70
|
+
# attach this commit to to form a new head (default: []).
|
71
|
+
# actor - The Grit::Actor details of the user making the commit
|
72
|
+
# (default: nil).
|
73
|
+
# last_tree - The String SHA1 of a tree to compare with in order to avoid
|
74
|
+
# making empty commits (default: nil).
|
75
|
+
# head - The String branch name to write this head to
|
76
|
+
# (default: "master").
|
77
|
+
#
|
78
|
+
# Returns a String of the SHA1 of the new commit.
|
79
|
+
def commit(message, parents = [], actor = nil, last_tree = nil, head = 'master')
|
49
80
|
tree_sha1 = write_tree(self.tree, self.current_tree)
|
50
|
-
|
81
|
+
|
82
|
+
# don't write identical commits
|
83
|
+
return false if tree_sha1 == last_tree
|
51
84
|
|
52
85
|
contents = []
|
53
86
|
contents << ['tree', tree_sha1].join(' ')
|
54
87
|
parents.each do |p|
|
55
|
-
contents << ['parent', p].join(' ')
|
56
|
-
end
|
88
|
+
contents << ['parent', p].join(' ')
|
89
|
+
end
|
57
90
|
|
58
91
|
if actor
|
59
92
|
name = actor.name
|
@@ -75,10 +108,15 @@ module Grit
|
|
75
108
|
self.repo.update_ref(head, commit_sha1)
|
76
109
|
end
|
77
110
|
|
78
|
-
# Recursively write a tree to the index
|
79
|
-
#
|
111
|
+
# Recursively write a tree to the index.
|
112
|
+
#
|
113
|
+
# tree - The Hash tree map:
|
114
|
+
# key - The String directory or filename.
|
115
|
+
# val - The Hash submap or the String contents of the file.
|
116
|
+
# now_tree - The Grit::Tree representing the a previous tree upon which
|
117
|
+
# this tree will be based (default: nil).
|
80
118
|
#
|
81
|
-
# Returns the SHA1 String of the tree
|
119
|
+
# Returns the String SHA1 String of the tree.
|
82
120
|
def write_tree(tree, now_tree = nil)
|
83
121
|
tree_contents = {}
|
84
122
|
|
@@ -104,16 +142,20 @@ module Grit
|
|
104
142
|
sha = [sha].pack("H*")
|
105
143
|
str = "%s %s\0%s" % ['40000', k, sha]
|
106
144
|
tree_contents[k + '/'] = str
|
145
|
+
when false
|
146
|
+
tree_contents.delete(k)
|
107
147
|
end
|
108
148
|
end
|
149
|
+
|
109
150
|
tr = tree_contents.sort.map { |k, v| v }.join('')
|
110
151
|
self.repo.git.put_raw_object(tr, 'tree')
|
111
152
|
end
|
112
153
|
|
113
|
-
# Write
|
114
|
-
#
|
154
|
+
# Write a blob to the index.
|
155
|
+
#
|
156
|
+
# data - The String data to write.
|
115
157
|
#
|
116
|
-
# Returns the SHA1
|
158
|
+
# Returns the String SHA1 of the new blob.
|
117
159
|
def write_blob(data)
|
118
160
|
self.repo.git.put_raw_object(data, 'blob')
|
119
161
|
end
|
data/lib/grit/status.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Preston-Werner
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2010-08-
|
13
|
+
date: 2010-08-19 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|