Skip to content

Commit 8f8182e

Browse files
committed
don't cram tags and branches and non commit hash revs into the sha field
1 parent 4775398 commit 8f8182e

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/crates/mod.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,29 @@ impl TryFrom<&'_ PackageId> for Crate {
142142
Ok(Crate::GitHub(GitHubRepo {
143143
org: org.to_string(),
144144
name: repo_name.to_string(),
145-
sha: rev.pretty_ref(false).map(|rev| rev.to_string()),
145+
sha: match rev {
146+
GitReference::Rev(rev)
147+
if rev.chars().all(|c| c.is_ascii_hexdigit()) =>
148+
{
149+
Some(rev.to_string())
150+
}
151+
_ => None,
152+
},
146153
}))
147154
} else {
148155
bail!("Github Git URL doesn't have a valid path")
149156
}
150157
} else {
151158
Ok(Crate::Git(GitRepo {
152159
url: url.to_string(),
153-
sha: rev.pretty_ref(false).map(|rev| rev.to_string()),
160+
sha: match rev {
161+
GitReference::Rev(rev)
162+
if rev.chars().all(|c| c.is_ascii_hexdigit()) =>
163+
{
164+
Some(rev.to_string())
165+
}
166+
_ => None,
167+
},
154168
}))
155169
}
156170
} else {
@@ -391,13 +405,13 @@ mod tests {
391405
"git+ssh://git@github.com/rust-lang/regex.git?branch=dev#regex@1.4.3" => Crate::GitHub(GitHubRepo {
392406
org: "rust-lang".to_string(),
393407
name: "regex".to_string(),
394-
sha: Some("branch=dev".to_string())
408+
sha: None
395409
}),
396410

397411
"git+https://gitlab.com/dummy_org/dummy?rev=9823f01cf4948a41279f6a3febcf793130cab4f6" => Crate::Git(GitRepo {
398412
url: "https://gitlab.com/dummy_org/dummy"
399413
.to_string(),
400-
sha: Some("rev=9823f01cf4948a41279f6a3febcf793130cab4f6".to_string())
414+
sha: Some("9823f01cf4948a41279f6a3febcf793130cab4f6".to_string())
401415
}),
402416

403417
"file:///path/to/my/project/foo" => Crate::Path("/path/to/my/project/foo".to_string()),

0 commit comments

Comments
 (0)