@@ -40,7 +40,7 @@ pub struct Remote {
4040 /// e.g. `master`
4141 pub branch : BranchName ,
4242 /// e.g. `1a2b3c`
43- pub commit : Option < Commit > ,
43+ pub commit : Option < CommitId > ,
4444}
4545
4646impl Remote {
@@ -104,7 +104,7 @@ pub struct PullRequest {
104104 /// Number of the pull request
105105 pub number : PrNumber ,
106106 /// Commit to checkout of the pull request. If none, uses the latest commit
107- pub commit : Option < Commit > ,
107+ pub commit : Option < CommitId > ,
108108}
109109
110110impl FromStr for PullRequest {
@@ -132,7 +132,7 @@ pub struct Branch {
132132 /// Name of the branch
133133 pub name : BranchName ,
134134 /// Commit to checkout when fetching this branch
135- pub commit : Option < Commit > ,
135+ pub commit : Option < CommitId > ,
136136}
137137
138138impl FromStr for Branch {
@@ -158,7 +158,7 @@ pub struct Ref {
158158 /// Git item. E.g. branch, or remote which may associate with the `commit`
159159 pub item : String ,
160160 /// Commit to checkout of the `item`. If none, uses the latest commit
161- pub commit : Option < Commit > ,
161+ pub commit : Option < CommitId > ,
162162}
163163
164164impl FromStr for Ref {
@@ -180,7 +180,7 @@ impl FromStr for Ref {
180180 } else {
181181 // They want to use a specific commit
182182 let head: String = parts[ 0 ..len - 1 ] . iter ( ) . map ( |s| String :: from ( * s) ) . collect ( ) ;
183- let commit = ( parts[ len - 1 ] . to_owned ( ) ) . parse :: < Commit > ( ) . ok ( ) ;
183+ let commit = ( parts[ len - 1 ] . to_owned ( ) ) . parse :: < CommitId > ( ) . ok ( ) ;
184184 Self { item : head, commit }
185185 }
186186 . pipe ( Ok )
@@ -259,12 +259,11 @@ impl Display for PatchName {
259259}
260260
261261/// Represents a git commit hash
262- // #[cfg_attr(test, nutype_test_util::derive(From))]
263262#[ nutype(
264263 validate( not_empty, predicate = is_valid_commit_hash) ,
265- derive( Debug , Eq , PartialEq , Ord , PartialOrd , Clone , AsRef , TryFrom )
264+ derive( Debug , Eq , PartialEq , Ord , PartialOrd , Clone , AsRef , TryFrom , FromStr )
266265) ]
267- pub struct Commit ( String ) ;
266+ pub struct CommitId ( String ) ;
268267
269268/// Does not check if the commit exists, just checks if it is potentially valid
270269///
@@ -273,17 +272,6 @@ pub fn is_valid_commit_hash(hash: &str) -> bool {
273272 hash. chars ( ) . all ( |ch| ch. is_ascii_hexdigit ( ) )
274273}
275274
276- impl FromStr for Commit {
277- type Err = String ;
278-
279- fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
280- Self :: try_new ( s) . map_err ( |err| match err {
281- CommitError :: NotEmptyViolated => "commit cannot be empty" . to_string ( ) ,
282- CommitError :: PredicateViolated => format ! ( "invalid commit hash: {s}" ) ,
283- } )
284- }
285- }
286-
287275/// Implement `Deserialize` for these types, given that they have a `FromStr` impl
288276// This is not a blanket impl as that would violate the orphan rule
289277macro_rules! impl_deserialize_for {
0 commit comments