File tree Expand file tree Collapse file tree 3 files changed +23
-12
lines changed Expand file tree Collapse file tree 3 files changed +23
-12
lines changed Original file line number Diff line number Diff line change @@ -954,6 +954,14 @@ describe "install" do
954
954
end
955
955
end
956
956
957
+ it " shows error when installing by ref and spec is invalid" do
958
+ metadata = {dependencies: {invalidspec: {git: git_url(:invalidspec ), tag: " v0.1.0" }}}
959
+ with_shard(metadata) do
960
+ ex = expect_raises(FailedCommand ) { run " shards install --no-color" }
961
+ ex.stdout.should contain(%( E: Invalid shard.yml for shard "invalidspec" at commit #{ git_commits(:invalidspec )[0 ] } : Expected SCALAR but was SEQUENCE_START at line 5, column 1) )
962
+ end
963
+ end
964
+
957
965
it " install latest version despite current crystal being older version, but warn" do
958
966
metadata = {dependencies: {incompatible: " *" }}
959
967
with_shard(metadata) do
Original file line number Diff line number Diff line change @@ -62,6 +62,9 @@ private def setup_repositories
62
62
create_git_release " noshardyml" , " 0.1.0" , false
63
63
create_git_release " noshardyml" , " 0.2.0"
64
64
65
+ create_git_repository " invalidspec"
66
+ create_git_release " invalidspec" , " 0.1.0" , {crystal: [" " ]}
67
+
65
68
# dependencies with postinstall scripts:
66
69
create_git_repository " post"
67
70
{% if flag?(:win32 ) % }
Original file line number Diff line number Diff line change @@ -152,15 +152,18 @@ module Shards
152
152
end
153
153
end
154
154
155
- private def spec_at_ref (ref : GitRef ) : Spec ?
155
+ private def spec_at_ref (ref : GitRef , commit ) : Spec
156
156
update_local_cache
157
+
158
+ unless file_exists?(ref, SPEC_FILENAME )
159
+ raise Error .new " No #{ SPEC_FILENAME } was found for shard #{ name.inspect } at commit #{ commit } "
160
+ end
161
+
162
+ spec_yaml = capture(" git show #{ Process .quote(" #{ ref.to_git_ref } :#{ SPEC_FILENAME } " )} " )
157
163
begin
158
- if file_exists?(ref, SPEC_FILENAME )
159
- spec_yaml = capture(" git show #{ Process .quote(" #{ ref.to_git_ref } :#{ SPEC_FILENAME } " )} " )
160
- Spec .from_yaml(spec_yaml)
161
- end
162
- rescue Error
163
- nil
164
+ Spec .from_yaml(spec_yaml)
165
+ rescue error : Error
166
+ raise Error .new " Invalid #{ SPEC_FILENAME } for shard #{ name.inspect } at commit #{ commit } : #{ error.message } "
164
167
end
165
168
end
166
169
@@ -183,11 +186,8 @@ module Shards
183
186
raise Error .new " Could not find #{ ref.full_info } for shard #{ name.inspect } in the repository #{ source } "
184
187
end
185
188
186
- if spec = spec_at_ref(ref)
187
- Version .new " #{ spec.version.value } +git.commit.#{ commit } "
188
- else
189
- raise Error .new " No #{ SPEC_FILENAME } was found for shard #{ name.inspect } at commit #{ commit } "
190
- end
189
+ spec = spec_at_ref(ref, commit)
190
+ Version .new " #{ spec.version.value } +git.commit.#{ commit } "
191
191
end
192
192
193
193
def matches_ref ?(ref : GitRef , version : Version )
You can’t perform that action at this time.
0 commit comments