File tree Expand file tree Collapse file tree 2 files changed +27
-8
lines changed Expand file tree Collapse file tree 2 files changed +27
-8
lines changed Original file line number Diff line number Diff line change @@ -87,7 +87,8 @@ struct VcsInfo {
87
87
88
88
#[ derive( Serialize ) ]
89
89
struct GitVcsInfo {
90
- sha1 : String ,
90
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
91
+ sha1 : Option < String > ,
91
92
/// Indicate whether or not the Git worktree is dirty.
92
93
#[ serde( skip_serializing_if = "std::ops::Not::not" ) ]
93
94
dirty : bool ,
@@ -799,9 +800,12 @@ fn check_repo_state(
799
800
. collect ( ) ;
800
801
let dirty = !dirty_src_files. is_empty ( ) ;
801
802
if !dirty || opts. allow_dirty {
803
+ if repo. is_empty ( ) ? {
804
+ return Ok ( GitVcsInfo { sha1 : None , dirty } ) ;
805
+ }
802
806
let rev_obj = repo. revparse_single ( "HEAD" ) ?;
803
807
Ok ( GitVcsInfo {
804
- sha1 : rev_obj. id ( ) . to_string ( ) ,
808
+ sha1 : Some ( rev_obj. id ( ) . to_string ( ) ) ,
805
809
dirty,
806
810
} )
807
811
} else {
Original file line number Diff line number Diff line change @@ -1273,13 +1273,28 @@ fn issue_14354_allowing_dirty_bare_commit() {
1273
1273
)
1274
1274
. file ( "src/lib.rs" , "" ) ;
1275
1275
1276
- p. cargo ( "package --allow-dirty" )
1277
- . with_status ( 101 )
1278
- . with_stderr_data ( str![ [ r#"
1279
- [ERROR] revspec 'HEAD' not found; class=Reference (4); code=NotFound (-3)
1276
+ p. cargo ( "package --allow-dirty" ) . run ( ) ;
1280
1277
1281
- "# ] ] )
1282
- . run ( ) ;
1278
+ let f = File :: open ( & p. root ( ) . join ( "target/package/foo-0.1.0.crate" ) ) . unwrap ( ) ;
1279
+ validate_crate_contents (
1280
+ f,
1281
+ "foo-0.1.0.crate" ,
1282
+ & [
1283
+ ".cargo_vcs_info.json" ,
1284
+ "Cargo.toml" ,
1285
+ "Cargo.toml.orig" ,
1286
+ "src/lib.rs" ,
1287
+ ] ,
1288
+ & [ (
1289
+ ".cargo_vcs_info.json" ,
1290
+ r#"{
1291
+ "git": {
1292
+ "dirty": true
1293
+ },
1294
+ "path_in_vcs": ""
1295
+ }"# ,
1296
+ ) ] ,
1297
+ ) ;
1283
1298
}
1284
1299
1285
1300
#[ cargo_test]
You can’t perform that action at this time.
0 commit comments