1+ //! Helpers to gather the VCS information for `cargo package`.
12use crate :: core:: { Package , Workspace } ;
2- use crate :: ops:: cargo_package:: vcs:: { GitVcsInfo , VcsInfo } ;
33use crate :: ops:: PackageOpts ;
44use crate :: sources:: PathEntry ;
55use crate :: { CargoResult , GlobalContext } ;
@@ -10,10 +10,28 @@ use gix::dir::walk::EmissionMode;
1010use gix:: index:: entry:: Mode ;
1111use gix:: status:: tree_index:: TrackRenames ;
1212use gix:: worktree:: stack:: state:: ignore:: Source ;
13+ use serde:: Serialize ;
1314use std:: collections:: HashSet ;
1415use std:: path:: { Path , PathBuf } ;
1516use tracing:: debug;
1617
18+ /// Represents the VCS information when packaging.
19+ #[ derive( Serialize ) ]
20+ pub struct VcsInfo {
21+ git : GitVcsInfo ,
22+ /// Path to the package within repo (empty string if root).
23+ path_in_vcs : String ,
24+ }
25+
26+ /// Represents the Git VCS information when packaging.
27+ #[ derive( Serialize ) ]
28+ pub struct GitVcsInfo {
29+ sha1 : String ,
30+ /// Indicate whether the Git worktree is dirty.
31+ #[ serde( skip_serializing_if = "std::ops::Not::not" ) ]
32+ dirty : bool ,
33+ }
34+
1735/// Checks if the package source is in a *git* DVCS repository.
1836///
1937/// If *git*, and the source is *dirty* (e.g., has uncommitted changes),
@@ -64,8 +82,6 @@ pub fn check_repo_state(
6482 workdir. display( )
6583 ) )
6684 } ) ?;
67- // TODO: Either remove this whole block, or have a test.
68- // It's hard to have no Cargo.toml here?
6985 // No `Cargo.toml` found. This package may be irrelevant.
7086 // Have to assume it is clean.
7187 return Ok ( None ) ;
0 commit comments