File tree Expand file tree Collapse file tree 7 files changed +60
-27
lines changed Expand file tree Collapse file tree 7 files changed +60
-27
lines changed Original file line number Diff line number Diff line change @@ -376,6 +376,32 @@ describe "install" do
376
376
end
377
377
end
378
378
379
+ it " warns when shard.yml version doesn't match git tag" do
380
+ metadata = {
381
+ dependencies: {
382
+ version_mismatch: {git: git_url(:version_mismatch ), version: " 0.2.0" },
383
+ },
384
+ }
385
+ with_shard(metadata) do
386
+ stdout = run " shards install --no-color"
387
+ stdout.should contain(" W: Shard \" version_mismatch\" version (0.1.0) doesn't match tag version (0.2.0)" )
388
+ assert_installed " version_mismatch"
389
+ end
390
+ end
391
+
392
+ it " doesn't warn when version mismatch is fixed" do
393
+ metadata = {
394
+ dependencies: {
395
+ version_mismatch: {git: git_url(:version_mismatch ), version: " 0.2.1" },
396
+ },
397
+ }
398
+ with_shard(metadata) do
399
+ stdout = run " shards install --no-color"
400
+ stdout.should_not contain(" doesn't match tag version" )
401
+ assert_installed " version_mismatch" , " 0.2.1"
402
+ end
403
+ end
404
+
379
405
it " test install old with version when shard was renamed" do
380
406
metadata = {
381
407
dependencies: {
Original file line number Diff line number Diff line change @@ -66,6 +66,11 @@ private def setup_repositories
66
66
create_git_release " renamed" , " 0.2.0" , " name: new_name\n version: 0.2.0"
67
67
create_git_version_commit " renamed" , " 0.3.0" , " name: another_name\n version: 0.3.0"
68
68
69
+ create_git_repository " version_mismatch"
70
+ create_git_release " version_mismatch" , " 0.1.0" , " name: version_mismatch\n version: 0.1.0"
71
+ create_git_release " version_mismatch" , " 0.2.0" , " name: version_mismatch\n version: 0.1.0"
72
+ create_git_release " version_mismatch" , " 0.2.1" , " name: version_mismatch\n version: 0.2.1"
73
+
69
74
create_git_repository " inprogress"
70
75
create_git_version_commit " inprogress" , " 0.1.0"
71
76
create_git_version_commit " inprogress" , " 0.1.0"
Original file line number Diff line number Diff line change @@ -70,6 +70,9 @@ module Shards
70
70
unless dependency.name == spec.name
71
71
raise Error .new(" Error shard name (#{ spec.name } ) doesn't match dependency name (#{ dependency.name } )" )
72
72
end
73
+ if spec.mismatched_version?
74
+ Log .warn { " Shard \" #{ spec.name } \" version (#{ spec.original_version } ) doesn't match tag version (#{ spec.version } )" }
75
+ end
73
76
end
74
77
resolver = spec.resolver || raise " BUG: returned Spec has no resolver"
75
78
version = spec.version
Original file line number Diff line number Diff line change @@ -41,23 +41,24 @@ module Shards
41
41
end
42
42
end
43
43
44
- def specs (versions )
45
- specs = {} of String => Spec
46
-
47
- versions.each do |version |
48
- refs = git_refs(version)
49
- yaml = capture(" git show #{ refs } :#{ SPEC_FILENAME } " )
50
- specs[version] = Spec .from_yaml(yaml).tap { |spec | spec.resolver = self }
51
- rescue Error
44
+ def spec (version = nil )
45
+ spec = Spec .from_yaml(read_spec(version))
46
+ spec.resolver = self
47
+
48
+ if version && version =~ VERSION_REFERENCE
49
+ # In this case, we know that the version was looked up by git tag, so we
50
+ # validate the spec version against the tag version.
51
+ version = version.lstrip('v' )
52
+ if spec.version != version
53
+ spec.mismatched_version = true
54
+ end
52
55
end
53
56
54
- specs
57
+ spec
55
58
end
56
59
57
- def spec ?(version)
58
- refs = git_refs(version)
59
- yaml = capture(" git show #{ refs } :#{ SPEC_FILENAME } " )
60
- Spec .from_yaml(yaml)
60
+ private def spec? (version )
61
+ spec(version)
61
62
rescue Error
62
63
end
63
64
Original file line number Diff line number Diff line change @@ -20,13 +20,10 @@ module Shards
20
20
@dependency .path
21
21
end
22
22
23
- def spec ?(version)
24
- spec_path = File .join(local_path, SPEC_FILENAME )
25
-
26
- if File .exists?(spec_path)
27
- Spec .from_yaml(File .read(spec_path))
28
- # TODO: fail if the spec isn't the expected version!
29
- end
23
+ def spec (version = nil )
24
+ spec = Spec .from_yaml(read_spec(version))
25
+ spec.resolver = self
26
+ spec
30
27
end
31
28
32
29
def installed_spec
Original file line number Diff line number Diff line change @@ -11,13 +11,12 @@ module Shards
11
11
def initialize (@dependency )
12
12
end
13
13
14
- def spec (version = nil )
15
- Spec .from_yaml(read_spec(version)).tap { |spec | spec.resolver = self }
16
- end
17
-
18
14
def specs (versions )
19
15
specs = {} of String => Spec
20
- versions.each { |version | specs[version] = spec(version) }
16
+ versions.each do |version |
17
+ specs[version] = spec(version)
18
+ rescue Error
19
+ end
21
20
specs
22
21
end
23
22
@@ -35,7 +34,7 @@ module Shards
35
34
end
36
35
37
36
abstract def read_spec (version = nil )
38
- abstract def spec ? (version)
37
+ abstract def spec (version )
39
38
abstract def available_versions
40
39
abstract def install (version = nil )
41
40
abstract def installed_commit_hash
Original file line number Diff line number Diff line change @@ -70,10 +70,12 @@ module Shards
70
70
71
71
getter! name : String ?
72
72
getter! version : String ?
73
+ getter! original_version : String ?
73
74
getter description : String ?
74
75
getter license : String ?
75
76
getter crystal : String ?
76
77
property resolver : Resolver ?
78
+ property? mismatched_version = false
77
79
78
80
# :nodoc:
79
81
def initialize (pull : YAML ::PullParser , validate = false )
@@ -84,7 +86,7 @@ module Shards
84
86
when " name"
85
87
@name = pull.read_scalar
86
88
when " version"
87
- @version = pull.read_scalar
89
+ @original_version = @ version = pull.read_scalar
88
90
when " description"
89
91
@description = pull.read_scalar
90
92
when " license"
You can’t perform that action at this time.
0 commit comments