File tree Expand file tree Collapse file tree 2 files changed +35
-8
lines changed Expand file tree Collapse file tree 2 files changed +35
-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,11 +800,13 @@ fn check_repo_state(
799
800
. collect ( ) ;
800
801
let dirty = !dirty_src_files. is_empty ( ) ;
801
802
if !dirty || opts. allow_dirty {
802
- let rev_obj = repo. revparse_single ( "HEAD" ) ?;
803
- Ok ( GitVcsInfo {
804
- sha1 : rev_obj. id ( ) . to_string ( ) ,
805
- dirty,
806
- } )
803
+ let sha1 = if let Ok ( rev_obj) = repo. revparse_single ( "HEAD" ) {
804
+ Some ( rev_obj. id ( ) . to_string ( ) )
805
+ } else {
806
+ None
807
+ } ;
808
+
809
+ Ok ( GitVcsInfo { sha1 : sha1, dirty } )
807
810
} else {
808
811
anyhow:: bail!(
809
812
"{} files in the working directory contain changes that were \
Original file line number Diff line number Diff line change @@ -1274,12 +1274,36 @@ fn issue_14354_allowing_bare_git_repo() {
1274
1274
. file ( "src/lib.rs" , "" ) ;
1275
1275
1276
1276
p. cargo ( "package --allow-dirty" )
1277
- . with_status ( 101 )
1278
1277
. with_stderr_data ( str![ [ r#"
1279
- [ERROR] revspec 'HEAD' not found; class=Reference (4); code=NotFound (-3)
1278
+ [PACKAGING] foo v0.1.0 ([ROOT]/foo)
1279
+ [PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
1280
+ [VERIFYING] foo v0.1.0 ([ROOT]/foo)
1281
+ [COMPILING] foo v0.1.0 ([ROOT]/foo/target/package/foo-0.1.0)
1282
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
1280
1283
1281
1284
"# ] ] )
1282
1285
. run ( ) ;
1286
+
1287
+ let f = File :: open ( & p. root ( ) . join ( "target/package/foo-0.1.0.crate" ) ) . unwrap ( ) ;
1288
+ validate_crate_contents (
1289
+ f,
1290
+ "foo-0.1.0.crate" ,
1291
+ & [
1292
+ ".cargo_vcs_info.json" ,
1293
+ "Cargo.toml" ,
1294
+ "Cargo.toml.orig" ,
1295
+ "src/lib.rs" ,
1296
+ ] ,
1297
+ & [ (
1298
+ ".cargo_vcs_info.json" ,
1299
+ r#"{
1300
+ "git": {
1301
+ "dirty": true
1302
+ },
1303
+ "path_in_vcs": ""
1304
+ }"# ,
1305
+ ) ] ,
1306
+ ) ;
1283
1307
}
1284
1308
1285
1309
#[ cargo_test]
You can’t perform that action at this time.
0 commit comments