Skip to content

change!: discard unbranched files if unbranched is not specified in the conversion parameters file #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## 0.3.0 (unreleased)

### Breaking

- Unbranched branch will not be created if `unbranched` is not specified in the
conversion parameters file.

### Other

- MSRV has been bumped to 1.82.

## 0.2.1 (2024-09-09)

### Changed
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "svn2git"
version = "0.2.1"
version = "0.3.0-pre"
authors = ["Eduardo Sánchez Muñoz <eduardosm-dev@e64.io>"]
edition = "2021"
rust-version = "1.82"
Expand All @@ -10,7 +10,7 @@ license = "MIT OR Apache-2.0"
keywords = ["converter", "git", "repository", "subversion", "svn"]
categories = ["development-tools"]
exclude = ["/.github", "/book", "/ci", ".gitignore"]
publish = true
publish = false

[[test]]
name = "convert"
Expand Down
5 changes: 3 additions & 2 deletions book/src/documentation/conv-params.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,11 @@
head = ""
```

* `unbranched-name` (default: `unbranched`)
* `unbranched-name`

Specifies the name of the Git branch where everything that is not part of a
branch or a tag (as specified with `branches` or `tags`) will be placed.
branch or a tag (as specified with `branches` or `tags`) will be placed. If
not specified, these files will be discarded.

<u>Example</u>

Expand Down
4 changes: 3 additions & 1 deletion convert-tests/defs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::BTreeMap;
use std::collections::{BTreeMap, BTreeSet};

#[derive(serde::Deserialize)]
#[serde(deny_unknown_fields)]
Expand All @@ -23,6 +23,8 @@ pub(crate) struct Test {
pub(crate) logs: Option<String>,
#[serde(rename = "git-tags", default = "Vec::new")]
pub(crate) git_tags: Vec<GitTag>,
#[serde(rename = "git-refs")]
pub(crate) git_refs: Option<BTreeSet<String>>,
#[serde(rename = "git-revs", default = "Vec::new")]
pub(crate) git_revs: Vec<GitRev>,
}
Expand Down
25 changes: 24 additions & 1 deletion convert-tests/test.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::BTreeMap;
use std::collections::{BTreeMap, BTreeSet};
use std::io::Write as _;
use std::path::{Path, PathBuf};

Expand Down Expand Up @@ -102,6 +102,29 @@ pub(crate) fn run_test(test_path: &Path) -> Result<(), String> {
let git_repo = gix::open(&git_repo_path)
.map_err(|e| format!("failed to open git repository {git_repo_path:?}: {e}"))?;

if let Some(ref expected_git_refs) = test_def.git_refs {
let mut actual_git_refs = BTreeSet::new();

let refs = git_repo
.refs
.iter()
.map_err(|e| format!("failed to get git refs: {e}"))?;
let refs_iter = refs
.all()
.map_err(|e| format!("failed to get git refs: {e}"))?;
for ref_ in refs_iter {
let ref_ = ref_.map_err(|e| format!("failed to get git refs: {e}"))?;
actual_git_refs.insert(ref_.name.to_string());
}

if actual_git_refs != *expected_git_refs {
return Err(format!(
"unexpected git refs:\nactual: {:?}\nexpected: {:?}",
actual_git_refs, expected_git_refs,
));
}
}

for git_tag in test_def.git_tags.iter() {
check_git_tag(&git_repo, git_tag)
.map_err(|e| format!("tag {:?} check failed: {e}", git_tag.tag))?;
Expand Down
45 changes: 45 additions & 0 deletions convert-tests/tests/branches/branched-discard-unbranched.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
svn-revs:
- props:
svn:log: create trunk
nodes:
- path: trunk
kind: dir
action: add
- path: trunk/x
kind: file
action: add
text: "x\n"
- props:
svn:log: create unbranched
nodes:
- path: y
kind: file
action: add
text: "y\n"
- path: directory
kind: dir
action: add
- path: directory/z
kind: file
action: add
text: "z\n"

conv-params: |
branches = ["trunk"]

logs: |
D svn2git::convert::stage1: importing SVN revision 1
D svn2git::convert::stage1: creating branch "trunk" with new directory
D svn2git::convert::stage1: importing SVN revision 2
D svn2git::convert::stage1: committed on unbranched branch

git-refs:
- refs/heads/trunk

git-revs:
- rev: trunk~0
parents: []
tree:
x:
type: normal
data: "x\n"
5 changes: 5 additions & 0 deletions convert-tests/tests/branches/branched-unbranched.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,18 @@ svn-revs:

conv-params: |
branches = ["trunk"]
unbranched-name = "unbranched"

logs: |
D svn2git::convert::stage1: importing SVN revision 1
D svn2git::convert::stage1: creating branch "trunk" with new directory
D svn2git::convert::stage1: importing SVN revision 2
D svn2git::convert::stage1: committed on unbranched branch

git-refs:
- refs/heads/trunk
- refs/heads/unbranched

git-revs:
- rev: trunk~0
parents: []
Expand Down
1 change: 1 addition & 0 deletions convert-tests/tests/branches/copy-nonbranch-to-one.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ conv-params: |
rename-branches."branches/*" = "*"

head = "branches/b1"
unbranched-name = "unbranched"

logs: |
D svn2git::convert::stage1: importing SVN revision 3
Expand Down
1 change: 1 addition & 0 deletions convert-tests/tests/branches/copy-nonbranch-to-parent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ svn-revs:
conv-params: |
branches = ["branches2/*"]
head = "branches2/b1"
unbranched-name = "unbranched"

logs: |
D svn2git::convert::stage1: importing SVN revision 2
Expand Down
1 change: 1 addition & 0 deletions convert-tests/tests/branches/copy-one-to-nonbranch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ svn-revs:
conv-params: |
branches = ["trunk"]
rename-branches."trunk" = "master"
unbranched-name = "unbranched"

logs: |
D svn2git::convert::stage1: importing SVN revision 3
Expand Down
1 change: 1 addition & 0 deletions convert-tests/tests/branches/copy-parent-to-nonbranch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ svn-revs:
conv-params: |
branches = ["branches1/*"]
head = "branches1/b1"
unbranched-name = "unbranched"

logs: |
D svn2git::convert::stage1: importing SVN revision 2
Expand Down
1 change: 1 addition & 0 deletions convert-tests/tests/commit-meta/custom.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ svn-revs:

conv-params: |
branches = ["trunk"]
unbranched-name = "unbranched"
user-map-file = "user-map.txt"
user-fallback-template = "{{ svn_author }} <unknown>"
commit-msg-template = """
Expand Down
1 change: 1 addition & 0 deletions convert-tests/tests/commit-meta/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ svn-revs:

conv-params: |
branches = ["trunk"]
unbranched-name = "unbranched"

git-revs:
- rev: trunk~2
Expand Down
1 change: 1 addition & 0 deletions convert-tests/tests/delete-files-unbranched.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ svn-revs:

conv-params: |
head = ""
unbranched-name = "unbranched"
delete-files = ["**/y"]

git-revs:
Expand Down
1 change: 1 addition & 0 deletions convert-tests/tests/head/unbranched.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ svn-revs:

conv-params: |
head = ""
unbranched-name = "unbranched"

git-revs:
- rev: HEAD
Expand Down
1 change: 1 addition & 0 deletions convert-tests/tests/ignore/disabled-unbranched.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ svn-revs:

conv-params: |
branches = ["trunk"]
unbranched-name = "unbranched"
generate-gitignore = false

git-revs:
Expand Down
1 change: 1 addition & 0 deletions convert-tests/tests/ignore/unbranched.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ svn-revs:

conv-params: |
branches = ["trunk"]
unbranched-name = "unbranched"

git-revs:
- rev: trunk~0
Expand Down
1 change: 1 addition & 0 deletions convert-tests/tests/ops-unbranched/basic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ svn-revs:

conv-params: |
head = ""
unbranched-name = "unbranched"

git-revs:
- rev: unbranched~0
Expand Down
1 change: 1 addition & 0 deletions convert-tests/tests/ops-unbranched/change-file-exec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ svn-revs:

conv-params: |
head = ""
unbranched-name = "unbranched"

git-revs:
- rev: unbranched~5
Expand Down
1 change: 1 addition & 0 deletions convert-tests/tests/ops-unbranched/copy-dir.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ svn-revs:

conv-params: |
head = ""
unbranched-name = "unbranched"

git-revs:
- rev: unbranched~1
Expand Down
1 change: 1 addition & 0 deletions convert-tests/tests/ops-unbranched/copy-file.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ svn-revs:

conv-params: |
head = ""
unbranched-name = "unbranched"

git-revs:
- rev: unbranched~1
Expand Down
1 change: 1 addition & 0 deletions convert-tests/tests/ops-unbranched/copy-modify-file.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ svn-revs:

conv-params: |
head = ""
unbranched-name = "unbranched"

git-revs:
- rev: unbranched~1
Expand Down
1 change: 1 addition & 0 deletions convert-tests/tests/ops-unbranched/copy-replace-file.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ svn-revs:

conv-params: |
head = ""
unbranched-name = "unbranched"

git-revs:
- rev: unbranched~1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ svn-revs:

conv-params: |
head = ""
unbranched-name = "unbranched"

git-revs:
- rev: unbranched~1
Expand Down
1 change: 1 addition & 0 deletions convert-tests/tests/ops-unbranched/delete-dir.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ svn-revs:

conv-params: |
head = ""
unbranched-name = "unbranched"

git-revs:
- rev: unbranched~1
Expand Down
1 change: 1 addition & 0 deletions convert-tests/tests/ops-unbranched/delete-file.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ svn-revs:

conv-params: |
head = ""
unbranched-name = "unbranched"

git-revs:
- rev: unbranched~1
Expand Down
1 change: 1 addition & 0 deletions convert-tests/tests/ops-unbranched/file-to-symlink.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ svn-revs:

conv-params: |
head = ""
unbranched-name = "unbranched"

git-revs:
- rev: unbranched~4
Expand Down
1 change: 1 addition & 0 deletions convert-tests/tests/ops-unbranched/modify-file.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ svn-revs:

conv-params: |
head = ""
unbranched-name = "unbranched"

git-revs:
- rev: unbranched~1
Expand Down
1 change: 1 addition & 0 deletions convert-tests/tests/ops-unbranched/replace-file.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ svn-revs:

conv-params: |
head = ""
unbranched-name = "unbranched"

git-revs:
- rev: unbranched~1
Expand Down
1 change: 1 addition & 0 deletions convert-tests/tests/prop-delta/ignore-unbranched.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ svn-revs:

conv-params: |
branches = ["trunk"]
unbranched-name = "unbranched"

git-revs:
- rev: trunk~0
Expand Down
6 changes: 3 additions & 3 deletions src/convert/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub(crate) struct InitOptions {
pub(crate) keep_deleted_branches: bool,
pub(crate) keep_deleted_tags: bool,
pub(crate) head_path: Vec<u8>,
pub(crate) unbranched_name: String,
pub(crate) unbranched_name: Option<String>,
pub(crate) enable_merges: bool,
pub(crate) merge_optional: PathPattern,
pub(crate) avoid_fully_reverted_merges: bool,
Expand All @@ -24,7 +24,7 @@ pub(crate) struct Options {
pub(super) rename_tags: BranchRenamer,
pub(super) keep_deleted_tags: bool,
pub(super) head_path: Vec<u8>,
pub(super) unbranched_name: String,
pub(super) unbranched_name: Option<String>,
pub(super) enable_merges: bool,
pub(super) merge_optional: PathPattern,
pub(super) avoid_fully_reverted_merges: bool,
Expand Down Expand Up @@ -278,7 +278,7 @@ mod tests {
keep_deleted_branches: true,
keep_deleted_tags: true,
head_path: b"trunk".to_vec(),
unbranched_name: "unbranched".into(),
unbranched_name: Some("unbranched".into()),
enable_merges: false,
merge_optional: PathPattern::default(),
avoid_fully_reverted_merges: false,
Expand Down
Loading