Skip to content

Commit

Permalink
Adding some SVN support
Browse files Browse the repository at this point in the history
  • Loading branch information
dertuxmalwieder committed Jul 27, 2021
1 parent d21c228 commit c603929
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 15 deletions.
16 changes: 15 additions & 1 deletion src/cargo/ops/cargo_new.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::core::{Edition, Shell, Workspace};
use crate::util::errors::CargoResult;
use crate::util::{existing_vcs_repo, FossilRepo, GitRepo, HgRepo, PijulRepo};
use crate::util::{existing_vcs_repo, FossilRepo, GitRepo, HgRepo, PijulRepo, SvnRepo};
use crate::util::{restricted_names, Config};
use anyhow::Context as _;
use cargo_util::paths;
Expand All @@ -19,6 +19,7 @@ pub enum VersionControl {
Hg,
Pijul,
Fossil,
Svn,
NoVcs,
}

Expand All @@ -31,6 +32,7 @@ impl FromStr for VersionControl {
"hg" => Ok(VersionControl::Hg),
"pijul" => Ok(VersionControl::Pijul),
"fossil" => Ok(VersionControl::Fossil),
"svn" => Ok(VersionControl::Svn),
"none" => Ok(VersionControl::NoVcs),
other => anyhow::bail!("unknown vcs specification: `{}`", other),
}
Expand Down Expand Up @@ -519,6 +521,11 @@ pub fn init(opts: &NewOptions, config: &Config) -> CargoResult<NewProjectKind> {
version_control = Some(VersionControl::Fossil);
num_detected_vsces += 1;
}

if path.join(".svn").exists() {
version_control = Some(VersionControl::Svn);
num_detected_vsces += 1;
}

// if none exists, maybe create git, like in `cargo new`

Expand Down Expand Up @@ -654,6 +661,8 @@ fn write_ignore_file(base_path: &Path, list: &IgnoreList, vcs: VersionControl) -
base_path.join(".fossil-settings/ignore-glob"),
base_path.join(".fossil-settings/clean-glob"),
],
// SVN uses propsets. This is left to be done here.
VersionControl::Svn => return Ok(()),
VersionControl::NoVcs => return Ok(()),
} {
let ignore: String = match paths::open(&fp_ignore) {
Expand Down Expand Up @@ -697,6 +706,11 @@ fn init_vcs(path: &Path, vcs: VersionControl, config: &Config) -> CargoResult<()
FossilRepo::init(path, config.cwd())?;
}
}
VersionControl::Svn => {
if !path.join(".svn").exists() {
SvnRepo::init(path, config.cwd())?;
}
}
VersionControl::NoVcs => {
paths::create_dir_all(path)?;
}
Expand Down
5 changes: 3 additions & 2 deletions src/cargo/util/command_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,12 @@ pub trait AppExt: Sized {
opt(
"vcs",
"Initialize a new repository for the given version \
control system (git, hg, pijul, or fossil) or do not \
control system (git, hg, pijul, fossil, or svn) or do not \
initialize any version control at all (none), overriding \
a global configuration.",
)
.value_name("VCS")
.possible_values(&["git", "hg", "pijul", "fossil", "none"]),
.possible_values(&["git", "hg", "pijul", "fossil", "svn", "none"]),
)
._arg(opt("bin", "Use a binary (application) template [default]"))
._arg(opt("lib", "Use a library template"))
Expand Down Expand Up @@ -584,6 +584,7 @@ pub trait ArgMatchesExt {
"hg" => VersionControl::Hg,
"pijul" => VersionControl::Pijul,
"fossil" => VersionControl::Fossil,
"svn" => VersionControl::Svn,
"none" => VersionControl::NoVcs,
vcs => panic!("Impossible vcs: {:?}", vcs),
});
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub use self::restricted_names::validate_package_name;
pub use self::rustc::Rustc;
pub use self::semver_ext::{OptVersionReq, VersionExt, VersionReqExt};
pub use self::to_semver::ToSemver;
pub use self::vcs::{existing_vcs_repo, FossilRepo, GitRepo, HgRepo, PijulRepo};
pub use self::vcs::{existing_vcs_repo, FossilRepo, GitRepo, HgRepo, PijulRepo, SvnRepo};
pub use self::workspace::{
add_path_args, path_args, print_available_benches, print_available_binaries,
print_available_examples, print_available_packages, print_available_tests,
Expand Down
25 changes: 25 additions & 0 deletions src/cargo/util/vcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::util::CargoResult;
use cargo_util::paths;
use cargo_util::ProcessBuilder;
use std::path::Path;
use url::Url;

// Check if we are in an existing repo. We define that to be true if either:
//
Expand Down Expand Up @@ -29,6 +30,7 @@ pub struct HgRepo;
pub struct GitRepo;
pub struct PijulRepo;
pub struct FossilRepo;
pub struct SvnRepo;

impl GitRepo {
pub fn init(path: &Path, _: &Path) -> CargoResult<GitRepo> {
Expand Down Expand Up @@ -98,3 +100,26 @@ impl FossilRepo {
Ok(FossilRepo)
}
}

impl SvnRepo {
pub fn init(path: &Path, cwd: &Path) -> CargoResult<SvnRepo> {
// SVN doesn't create the directory so we'll do that first.
paths::create_dir_all(path)?;

// Create a repository ...
ProcessBuilder::new("svnadmin")
.cwd(cwd)
.arg("create")
.arg(path)
.exec()?;

// ... and check it out:
let filepath = Url::from_file_path(path).unwrap();
ProcessBuilder::new("svn")
.cwd(cwd)
.arg("checkout")
.arg(filepath.as_str())
.exec()?;
Ok(SvnRepo)
}
}
2 changes: 1 addition & 1 deletion src/doc/man/includes/options-new.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Set the package name. Defaults to the directory name.

{{#option "`--vcs` _vcs_" }}
Initialize a new VCS repository for the given version control system (git,
hg, pijul, or fossil) or do not initialize any version control at all
hg, pijul, fossil, or svn) or do not initialize any version control at all
(none). If not specified, defaults to `git` or the configuration value
`cargo-new.vcs`, or `none` if already inside a VCS repository.
{{/option}}
Expand Down
2 changes: 1 addition & 1 deletion src/doc/src/commands/cargo-init.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Possible values: 2015, 2018, 2021</dd>

<dt class="option-term" id="option-cargo-init---vcs"><a class="option-anchor" href="#option-cargo-init---vcs"></a><code>--vcs</code> <em>vcs</em></dt>
<dd class="option-desc">Initialize a new VCS repository for the given version control system (git,
hg, pijul, or fossil) or do not initialize any version control at all
hg, pijul, fossil, or svn) or do not initialize any version control at all
(none). If not specified, defaults to <code>git</code> or the configuration value
<code>cargo-new.vcs</code>, or <code>none</code> if already inside a VCS repository.</dd>

Expand Down
2 changes: 1 addition & 1 deletion src/doc/src/commands/cargo-new.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Possible values: 2015, 2018, 2021</dd>

<dt class="option-term" id="option-cargo-new---vcs"><a class="option-anchor" href="#option-cargo-new---vcs"></a><code>--vcs</code> <em>vcs</em></dt>
<dd class="option-desc">Initialize a new VCS repository for the given version control system (git,
hg, pijul, or fossil) or do not initialize any version control at all
hg, pijul, fossil, or svn) or do not initialize any version control at all
(none). If not specified, defaults to <code>git</code> or the configuration value
<code>cargo-new.vcs</code>, or <code>none</code> if already inside a VCS repository.</dd>

Expand Down
8 changes: 4 additions & 4 deletions src/doc/src/reference/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ browser = "chromium" # browser to use with `cargo doc --open`,
# overrides the `BROWSER` environment variable

[cargo-new]
vcs = "none" # VCS to use ('git', 'hg', 'pijul', 'fossil', 'none')
vcs = "none" # VCS to use ('git', 'hg', 'pijul', 'fossil', 'svn', 'none')

[http]
debug = false # HTTP debugging
Expand Down Expand Up @@ -447,9 +447,9 @@ This option is deprecated and unused.
* Environment: `CARGO_CARGO_NEW_VCS`

Specifies the source control system to use for initializing a new repository.
Valid values are `git`, `hg` (for Mercurial), `pijul`, `fossil` or `none` to
disable this behavior. Defaults to `git`, or `none` if already inside a VCS
repository. Can be overridden with the `--vcs` CLI option.
Valid values are `git`, `hg` (for Mercurial), `pijul`, `fossil`, `svn`, or
`none` to disable this behavior. Defaults to `git`, or `none` if already inside
a VCS repository. Can be overridden with the `--vcs` CLI option.

#### `[http]`

Expand Down
4 changes: 2 additions & 2 deletions src/etc/_cargo
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ _cargo() {
_arguments -s -S $common $registry \
'--lib[use library template]' \
'--edition=[specify edition to set for the crate generated]:edition:(2015 2018 2021)' \
'--vcs=[initialize a new repo with a given VCS]:vcs:(git hg pijul fossil none)' \
'--vcs=[initialize a new repo with a given VCS]:vcs:(git hg pijul fossil svn none)' \
'--name=[set the resulting package name]:name' \
'1:path:_directories'
;;
Expand Down Expand Up @@ -179,7 +179,7 @@ _cargo() {
new)
_arguments -s -S $common $registry \
'--lib[use library template]' \
'--vcs:initialize a new repo with a given VCS:(git hg none)' \
'--vcs:initialize a new repo with a given VCS:(git hg pijul fossil svn none)' \
'--name=[set the resulting package name]'
;;

Expand Down
2 changes: 1 addition & 1 deletion src/etc/man/cargo-init.1
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Set the package name. Defaults to the directory name.
\fB\-\-vcs\fR \fIvcs\fR
.RS 4
Initialize a new VCS repository for the given version control system (git,
hg, pijul, or fossil) or do not initialize any version control at all
hg, pijul, fossil, or svn) or do not initialize any version control at all
(none). If not specified, defaults to \fBgit\fR or the configuration value
\fBcargo\-new.vcs\fR, or \fBnone\fR if already inside a VCS repository.
.RE
Expand Down
2 changes: 1 addition & 1 deletion src/etc/man/cargo-new.1
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Set the package name. Defaults to the directory name.
\fB\-\-vcs\fR \fIvcs\fR
.RS 4
Initialize a new VCS repository for the given version control system (git,
hg, pijul, or fossil) or do not initialize any version control at all
hg, pijul, fossil, or svn) or do not initialize any version control at all
(none). If not specified, defaults to \fBgit\fR or the configuration value
\fBcargo\-new.vcs\fR, or \fBnone\fR if already inside a VCS repository.
.RE
Expand Down

0 comments on commit c603929

Please sign in to comment.