treet 0.13.1 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/treet/gitrepo.rb +18 -12
- data/lib/treet/version.rb +1 -1
- data/spec/lib/test_gitrepo.rb +27 -19
- metadata +4 -4
data/lib/treet/gitrepo.rb
CHANGED
@@ -25,19 +25,25 @@ class Treet::Gitrepo < Treet::Repo
|
|
25
25
|
gitrepo.refs(/tags/)
|
26
26
|
end
|
27
27
|
|
28
|
-
def tag(tagname)
|
28
|
+
def tag(tagname, opts = {})
|
29
29
|
refname = "refs/tags/#{tagname}"
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
30
|
+
commit = opts[:commit] || head.target
|
31
|
+
if tag_ref = Rugged::Reference.lookup(gitrepo, refname)
|
32
|
+
# move an existing tag
|
33
|
+
tag_ref.target = commit
|
34
|
+
else
|
35
|
+
# new tag
|
36
|
+
Rugged::Reference.create(gitrepo, refname, commit)
|
37
|
+
end
|
38
|
+
rescue Rugged::ReferenceError, Rugged::InvalidError => e
|
39
|
+
# invalid string for source, e.g. blank or illegal punctuation (colons)
|
40
|
+
# or opts[:commit] is invalid
|
41
|
+
raise ArgumentError, "unable to tag '#{tagname}' on repo: #{e.message}"
|
42
|
+
end
|
43
|
+
|
44
|
+
def detag(tagname)
|
45
|
+
if tag_ref = Rugged::Reference.lookup(gitrepo, "refs/tags/#{tagname}")
|
46
|
+
tag_ref.delete!
|
41
47
|
end
|
42
48
|
end
|
43
49
|
|
data/lib/treet/version.rb
CHANGED
data/spec/lib/test_gitrepo.rb
CHANGED
@@ -8,7 +8,7 @@ require "test_helper"
|
|
8
8
|
# patch a gitrepo (with commit) - verify commit structure
|
9
9
|
# pulling past snapshots
|
10
10
|
|
11
|
-
|
11
|
+
class GitrepoTests < MiniTest::Spec
|
12
12
|
def self.make_gitrepo(filename, opts = {})
|
13
13
|
thash = Treet::Hash.new(load_json(filename))
|
14
14
|
trepo = thash.to_repo(Dir.mktmpdir('repo', $topdir))
|
@@ -123,8 +123,8 @@ describe Treet::Gitrepo do
|
|
123
123
|
|
124
124
|
|
125
125
|
describe "a patched gitrepo" do
|
126
|
-
def
|
127
|
-
|
126
|
+
def repo
|
127
|
+
@@repo_patch ||= begin
|
128
128
|
data = {
|
129
129
|
"name" => {
|
130
130
|
"full" => "John Bigbooté"
|
@@ -133,18 +133,17 @@ describe Treet::Gitrepo do
|
|
133
133
|
thash = Treet::Hash.new(data)
|
134
134
|
trepo = thash.to_repo(Dir.mktmpdir('repo', $topdir))
|
135
135
|
r = Treet::Gitrepo.new(trepo.root, :author => {:name => 'Bob', :email => 'bob@example.com'})
|
136
|
-
r.
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
])
|
136
|
+
@@v1 = r.version
|
137
|
+
r.patch([["+", "org.name", "Bigcorp"]])
|
138
|
+
@@v2 = r.version
|
139
|
+
r.patch([["+", "name.first", "John"], ["+", "name.last", "Bigbooté"]])
|
140
|
+
@@v3 = r.version
|
141
|
+
r.patch([["+", "name.last", "Bigbritches"]])
|
143
142
|
r
|
144
143
|
end
|
145
144
|
end
|
146
145
|
|
147
|
-
let(:repo) { self.class.patch_johnb }
|
146
|
+
# let(:repo) { self.class.patch_johnb }
|
148
147
|
|
149
148
|
it "should have correct git index" do
|
150
149
|
repo.index.count.must_equal 2
|
@@ -153,26 +152,35 @@ describe Treet::Gitrepo do
|
|
153
152
|
end
|
154
153
|
|
155
154
|
it "should hashify correctly" do
|
156
|
-
expectation =
|
155
|
+
expectation = {
|
156
|
+
'name' => {'full' => 'John Bigbooté', 'first' => 'John', 'last' => 'Bigbritches'},
|
157
|
+
'org' => {'name' => 'Bigcorp'}
|
158
|
+
}
|
157
159
|
repo.to_hash.must_equal expectation
|
158
160
|
end
|
159
161
|
|
160
162
|
it "should have 2 commits" do
|
161
163
|
r = Rugged::Repository.new(repo.root)
|
162
164
|
latest_commit = r.head.target
|
163
|
-
|
164
|
-
|
165
|
-
|
165
|
+
walker = Rugged::Walker.new(r)
|
166
|
+
walker.push(latest_commit)
|
167
|
+
walker.count.must_equal 4
|
166
168
|
end
|
167
169
|
|
168
170
|
it "should have no tags" do
|
169
171
|
repo.tags.must_be_empty
|
170
172
|
end
|
171
173
|
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
174
|
+
it "should be able to attach tags to commits" do
|
175
|
+
repo.tag('foo')
|
176
|
+
repo.version(:tag => 'foo').must_equal repo.version
|
177
|
+
repo.tag('foo', :commit => @@v1)
|
178
|
+
repo.version(:tag => 'foo').must_equal @@v1
|
179
|
+
repo.version(:tag => 'foo').wont_equal repo.version
|
180
|
+
->{repo.tag('foo', :commit => 'junk')}.must_raise ArgumentError
|
181
|
+
->{repo.tag('foo', :commit => @@v2.reverse)}.must_raise ArgumentError
|
182
|
+
repo.detag('foo')
|
183
|
+
end
|
176
184
|
end
|
177
185
|
|
178
186
|
describe "patched with a delete" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: treet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.14.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-04-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thor
|
@@ -206,7 +206,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
206
206
|
version: '0'
|
207
207
|
segments:
|
208
208
|
- 0
|
209
|
-
hash:
|
209
|
+
hash: 3982221712391638709
|
210
210
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
211
211
|
none: false
|
212
212
|
requirements:
|
@@ -215,7 +215,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
215
215
|
version: '0'
|
216
216
|
segments:
|
217
217
|
- 0
|
218
|
-
hash:
|
218
|
+
hash: 3982221712391638709
|
219
219
|
requirements: []
|
220
220
|
rubyforge_project:
|
221
221
|
rubygems_version: 1.8.24
|