-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathuntracked_detection.rs
More file actions
107 lines (85 loc) · 3.64 KB
/
untracked_detection.rs
File metadata and controls
107 lines (85 loc) · 3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#[path = "common/mod.rs"]
pub mod common;
use common::{
checkout_branch, commit_all, create_branch, create_new_file, first_commit_all,
generate_path_to_repo, get_current_branch_name, run_test_bin_expect_err,
run_test_bin_expect_ok, setup_git_repo, teardown_git_repo,
};
#[test]
fn backup_fails_with_untracked_files() {
let repo_name = "backup_fails_with_untracked";
let repo = setup_git_repo(repo_name);
let path_to_repo = generate_path_to_repo(repo_name);
// initial commit on master
create_new_file(&path_to_repo, "initial.txt", "initial");
first_commit_all(&repo, "initial commit");
// create feature branch
create_branch(&repo, "feature");
checkout_branch(&repo, "feature");
create_new_file(&path_to_repo, "feature.txt", "feature");
commit_all(&repo, "feature commit");
// initialize chain with root master
let args = vec!["init", "chain", "master"];
run_test_bin_expect_ok(&path_to_repo, args);
// add untracked file
create_new_file(&path_to_repo, "untracked.txt", "dirty");
// attempt backup and expect failure mentioning branch name
let args = vec!["backup"];
let output = run_test_bin_expect_err(&path_to_repo, args);
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(stderr.contains("uncommitted"));
assert!(stderr.contains(&get_current_branch_name(&repo)));
teardown_git_repo(repo_name);
}
#[test]
fn merge_fails_with_untracked_files() {
let repo_name = "merge_fails_with_untracked";
let repo = setup_git_repo(repo_name);
let path_to_repo = generate_path_to_repo(repo_name);
// initial commit on master
create_new_file(&path_to_repo, "initial.txt", "initial");
first_commit_all(&repo, "initial commit");
// create feature branch and commit
create_branch(&repo, "feature");
checkout_branch(&repo, "feature");
create_new_file(&path_to_repo, "feature.txt", "feature");
commit_all(&repo, "feature commit");
// initialize chain with root master
let args = vec!["init", "chain", "master"];
run_test_bin_expect_ok(&path_to_repo, args);
// add untracked file
create_new_file(&path_to_repo, "untracked.txt", "dirty");
// attempt merge and expect failure mentioning branch name
let args = vec!["merge"];
let output = run_test_bin_expect_err(&path_to_repo, args);
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(stderr.contains("uncommitted"));
assert!(stderr.contains(&get_current_branch_name(&repo)));
teardown_git_repo(repo_name);
}
#[test]
fn rebase_fails_with_untracked_files() {
let repo_name = "rebase_fails_with_untracked";
let repo = setup_git_repo(repo_name);
let path_to_repo = generate_path_to_repo(repo_name);
// initial commit on master
create_new_file(&path_to_repo, "initial.txt", "initial");
first_commit_all(&repo, "initial commit");
// create feature branch and commit
create_branch(&repo, "feature");
checkout_branch(&repo, "feature");
create_new_file(&path_to_repo, "feature.txt", "feature");
commit_all(&repo, "feature commit");
// initialize chain with root master
let args = vec!["init", "chain", "master"];
run_test_bin_expect_ok(&path_to_repo, args);
// add untracked file
create_new_file(&path_to_repo, "untracked.txt", "dirty");
// attempt rebase and expect failure mentioning branch name
let args = vec!["rebase"];
let output = run_test_bin_expect_err(&path_to_repo, args);
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(stderr.contains("uncommitted"));
assert!(stderr.contains(&get_current_branch_name(&repo)));
teardown_git_repo(repo_name);
}