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