Skip to content

Commit 2e928b2

Browse files
committed
Test dependencies on git tags and branches
1 parent b2a6392 commit 2e928b2

File tree

7 files changed

+97
-22
lines changed

7 files changed

+97
-22
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cành
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
name = "branch-leaf",
3+
version = "0.1.0",
4+
nickel_version = "1.9.0",
5+
dependencies = {},
6+
} | std.package.Manifest
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
name = "leaf",
3+
version = "0.1.0",
4+
nickel_version = "1.9.0",
5+
dependencies = {},
6+
} | std.package.Manifest
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mytag
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
name = "single-git-dep",
3+
version = "0.1.0",
4+
nickel_version = "1.9.0",
5+
dependencies = {
6+
branch = 'Git { url = "https://example.com/branch-leaf", ref = 'Branch "cành" },
7+
tag = 'Git { url = "https://example.com/tag-leaf", ref = 'Tag "mytag" },
8+
},
9+
} | std.package.Manifest

package/tests/integration/main.rs

+30-22
Original file line numberDiff line numberDiff line change
@@ -39,32 +39,41 @@ fn set_up_git_repos(config: &mut Config) -> TempDir {
3939
let file_name = input_path.file_name().unwrap();
4040

4141
let dir_path = tmp.path().join(file_name);
42-
// TODO: allow some annotations for configuring the git structure. (e.g. branches/tags)
42+
43+
let run = |cmd: &mut Command| {
44+
assert!(cmd.output().unwrap().status.success());
45+
};
46+
47+
let run_in_dir = |cmd: &mut Command| {
48+
run(cmd.current_dir(&dir_path));
49+
};
4350

4451
// The rust stdlib doesn't have anything for recursively copying a directory. There are
4552
// some crates for that, but it's easier just to shell out.
46-
Command::new("cp")
53+
run(Command::new("cp")
4754
.arg("-r")
4855
.arg(&input_path)
49-
.arg(tmp.path())
50-
.output()
51-
.unwrap();
52-
53-
Command::new("git")
54-
.arg("init")
55-
.current_dir(&dir_path)
56-
.output()
57-
.unwrap();
58-
Command::new("git")
59-
.args(["add", "--all"])
60-
.current_dir(&dir_path)
61-
.output()
62-
.unwrap();
63-
Command::new("git")
64-
.args(["commit", "-m", "initial"])
65-
.current_dir(&dir_path)
66-
.output()
67-
.unwrap();
56+
.arg(tmp.path()));
57+
58+
// We have some hacky ways to test branch/tag fetching: if the input contains a tag.txt file,
59+
// make a git tag named with the contents of that file. If the input contains a branch.txt file,
60+
// make a git branch named with the contents of that file.
61+
let tag = std::fs::read_to_string(dir_path.join("tag.txt")).ok();
62+
let branch = std::fs::read_to_string(dir_path.join("branch.txt")).ok();
63+
64+
run_in_dir(Command::new("git").arg("init"));
65+
66+
if let Some(branch) = branch {
67+
run_in_dir(Command::new("git").args(["commit", "-m", "initial", "--allow-empty"]));
68+
run_in_dir(Command::new("git").args(["checkout", "-b", branch.trim()]));
69+
}
70+
71+
run_in_dir(Command::new("git").args(["add", "--all"]));
72+
run_in_dir(Command::new("git").args(["commit", "-m", "initial"]));
73+
74+
if let Some(tag) = tag {
75+
run_in_dir(Command::new("git").args(["tag", tag.trim()]));
76+
}
6877

6978
let orig_url = gix::Url::try_from(format!(
7079
"https://example.com/{}",
@@ -86,7 +95,6 @@ fn generate_lock_file(path: &str) {
8695
let mut config = Config::default().with_cache_dir(cache_dir.path().to_owned());
8796

8897
let _git_dir = set_up_git_repos(&mut config);
89-
dbg!(_git_dir.into_path());
9098

9199
// Make an empty git repo as the index.
92100
Command::new("git")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
source: package/tests/integration/main.rs
3+
expression: lock_contents
4+
---
5+
{
6+
"dependencies": {
7+
"branch": {
8+
"Git": {
9+
"url": "https://example.com/branch-leaf",
10+
"id": <GENERATED>,
11+
"path": ""
12+
}
13+
},
14+
"tag": {
15+
"Git": {
16+
"url": "https://example.com/tag-leaf",
17+
"id": <GENERATED>,
18+
"path": ""
19+
}
20+
}
21+
},
22+
"packages": [
23+
{
24+
"source": {
25+
"Git": {
26+
"url": "https://example.com/branch-leaf",
27+
"id": <GENERATED>,
28+
"path": ""
29+
}
30+
},
31+
"dependencies": {}
32+
},
33+
{
34+
"source": {
35+
"Git": {
36+
"url": "https://example.com/tag-leaf",
37+
"id": <GENERATED>,
38+
"path": ""
39+
}
40+
},
41+
"dependencies": {}
42+
}
43+
]
44+
}

0 commit comments

Comments
 (0)