@@ -740,48 +740,69 @@ fn check_repo_state(
740
740
gctx : & GlobalContext ,
741
741
opts : & PackageOpts < ' _ > ,
742
742
) -> CargoResult < Option < VcsInfo > > {
743
- if let Ok ( repo) = git2:: Repository :: discover ( p. root ( ) ) {
744
- if let Some ( workdir) = repo. workdir ( ) {
745
- debug ! ( "found a git repo at {:?}" , workdir) ;
746
- let path = p. manifest_path ( ) ;
747
- let path =
748
- paths:: strip_prefix_canonical ( path, workdir) . unwrap_or_else ( |_| path. to_path_buf ( ) ) ;
749
- if let Ok ( status) = repo. status_file ( & path) {
750
- if ( status & git2:: Status :: IGNORED ) . is_empty ( ) {
751
- debug ! (
752
- "found (git) Cargo.toml at {:?} in workdir {:?}" ,
753
- path, workdir
754
- ) ;
755
- let path_in_vcs = path
756
- . parent ( )
757
- . and_then ( |p| p. to_str ( ) )
758
- . unwrap_or ( "" )
759
- . replace ( "\\ " , "/" ) ;
760
- let Some ( git) = git ( p, src_files, & repo, & opts) ? else {
761
- // If the git repo lacks essensial field like `sha1`, and since this field exists from the beginning,
762
- // then don't generate the corresponding file in order to maintain consistency with past behavior.
763
- return Ok ( None ) ;
764
- } ;
765
- return Ok ( Some ( VcsInfo { git, path_in_vcs } ) ) ;
766
- }
767
- }
768
- gctx. shell ( ) . verbose ( |shell| {
769
- shell. warn ( format ! (
770
- "no (git) Cargo.toml found at `{}` in workdir `{}`" ,
771
- path. display( ) ,
772
- workdir. display( )
773
- ) )
774
- } ) ?;
775
- }
776
- } else {
743
+ let Ok ( repo) = git2:: Repository :: discover ( p. root ( ) ) else {
777
744
gctx. shell ( ) . verbose ( |shell| {
778
745
shell. warn ( format ! ( "no (git) VCS found for `{}`" , p. root( ) . display( ) ) )
779
746
} ) ?;
747
+ // No Git repo found. Have to assume it is clean.
748
+ return Ok ( None ) ;
749
+ } ;
750
+
751
+ let Some ( workdir) = repo. workdir ( ) else {
752
+ debug ! (
753
+ "no (git) workdir found for repo at `{}`" ,
754
+ repo. path( ) . display( )
755
+ ) ;
756
+ // No git workdir. Have to assume it is clean.
757
+ return Ok ( None ) ;
758
+ } ;
759
+
760
+ debug ! ( "found a git repo at `{}`" , workdir. display( ) ) ;
761
+ let path = p. manifest_path ( ) ;
762
+ let path = paths:: strip_prefix_canonical ( path, workdir) . unwrap_or_else ( |_| path. to_path_buf ( ) ) ;
763
+ let Ok ( status) = repo. status_file ( & path) else {
764
+ gctx. shell ( ) . verbose ( |shell| {
765
+ shell. warn ( format ! (
766
+ "no (git) Cargo.toml found at `{}` in workdir `{}`" ,
767
+ path. display( ) ,
768
+ workdir. display( )
769
+ ) )
770
+ } ) ?;
771
+ // No checked-in `Cargo.toml` found. This package may be irrelevant.
772
+ // Have to assume it is clean.
773
+ return Ok ( None ) ;
774
+ } ;
775
+
776
+ if !( status & git2:: Status :: IGNORED ) . is_empty ( ) {
777
+ gctx. shell ( ) . verbose ( |shell| {
778
+ shell. warn ( format ! (
779
+ "found (git) Cargo.toml ignored at `{}` in workdir `{}`" ,
780
+ path. display( ) ,
781
+ workdir. display( )
782
+ ) )
783
+ } ) ?;
784
+ // An ignored `Cargo.toml` found. This package may be irrelevant.
785
+ // Have to assume it is clean.
786
+ return Ok ( None ) ;
780
787
}
781
788
782
- // No VCS with a checked in `Cargo.toml` found, so we don't know if the
783
- // directory is dirty or not, thus we have to assume that it's clean.
784
- return Ok ( None ) ;
789
+ debug ! (
790
+ "found (git) Cargo.toml at `{}` in workdir `{}`" ,
791
+ path. display( ) ,
792
+ workdir. display( ) ,
793
+ ) ;
794
+ let path_in_vcs = path
795
+ . parent ( )
796
+ . and_then ( |p| p. to_str ( ) )
797
+ . unwrap_or ( "" )
798
+ . replace ( "\\ " , "/" ) ;
799
+ let Some ( git) = git ( p, src_files, & repo, & opts) ? else {
800
+ // If the git repo lacks essensial field like `sha1`, and since this field exists from the beginning,
801
+ // then don't generate the corresponding file in order to maintain consistency with past behavior.
802
+ return Ok ( None ) ;
803
+ } ;
804
+
805
+ return Ok ( Some ( VcsInfo { git, path_in_vcs } ) ) ;
785
806
786
807
fn git (
787
808
pkg : & Package ,
0 commit comments