Skip to content

Commit 09cc2f2

Browse files
committed
add --no-vcs option to cargo package
If `cargo package` is run for a crate that is not version controlled in a way that cargo expects, git2 will overreach upwards and grab a irrelevant .git repo. This change adds `--no-vcs` as an option to `cargo package` to prevent this.
1 parent 1f730be commit 09cc2f2

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

src/bin/cargo/commands/package.rs

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ pub fn cli() -> App {
2323
"allow-dirty",
2424
"Allow dirty working directories to be packaged",
2525
))
26+
.arg(opt(
27+
"no-vcs",
28+
"Ignore version control for packaging",
29+
))
2630
.arg_target_triple("Build for the target triple")
2731
.arg_target_dir()
2832
.arg_manifest_path()
@@ -39,6 +43,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
3943
list: args.is_present("list"),
4044
check_metadata: !args.is_present("no-metadata"),
4145
allow_dirty: args.is_present("allow-dirty"),
46+
use_vcs: !args.is_present("no-vcs"),
4247
target: args.target(),
4348
jobs: args.jobs()?,
4449
registry: None,

src/cargo/ops/cargo_package.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub struct PackageOpts<'cfg> {
2424
pub check_metadata: bool,
2525
pub allow_dirty: bool,
2626
pub verify: bool,
27+
pub use_vcs: bool,
2728
pub jobs: Option<u32>,
2829
pub target: Option<String>,
2930
pub registry: Option<String>,
@@ -55,8 +56,12 @@ pub fn package(ws: &Workspace, opts: &PackageOpts) -> CargoResult<Option<FileLoc
5556
// Check (git) repository state, getting the current commit hash if not
5657
// dirty. This will `bail!` if dirty, unless allow_dirty. Produce json
5758
// info for any sha1 (HEAD revision) returned.
58-
let vcs_info = check_repo_state(pkg, &src_files, &config, opts.allow_dirty)?
59-
.map(|h| json!({"git":{"sha1": h}}));
59+
let vcs_info = if opts.use_vcs {
60+
check_repo_state(pkg, &src_files, &config, opts.allow_dirty)?
61+
.map(|h| json!({"git":{"sha1": h}}))
62+
} else {
63+
None
64+
};
6065

6166
if opts.list {
6267
let root = pkg.root();

src/cargo/ops/registry.rs

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ pub fn publish(ws: &Workspace, opts: &PublishOpts) -> CargoResult<()> {
8080
list: false,
8181
check_metadata: true,
8282
allow_dirty: opts.allow_dirty,
83+
use_vcs: true,
8384
target: opts.target.clone(),
8485
jobs: opts.jobs,
8586
registry: opts.registry.clone(),

0 commit comments

Comments
 (0)