-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #416 from epage/fix
fix: Skip allowed prefixes
- Loading branch information
Showing
5 changed files
with
159 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,10 @@ jobs: | |
toolchain: ${{ matrix.rust }} | ||
- uses: Swatinem/rust-cache@v2 | ||
- uses: taiki-e/install-action@cargo-hack | ||
- name: Configure git | ||
run: | | ||
git config --global user.name "Test User" | ||
git config --global user.email "[email protected]" | ||
- name: Build | ||
run: cargo test --workspace --no-run | ||
- name: Test | ||
|
@@ -149,6 +153,10 @@ jobs: | |
with: | ||
toolchain: stable | ||
- uses: Swatinem/rust-cache@v2 | ||
- name: Configure git | ||
run: | | ||
git config --global user.name "Test User" | ||
git config --global user.email "[email protected]" | ||
- name: Install cargo-tarpaulin | ||
run: cargo install cargo-tarpaulin | ||
- name: Gather coverage | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,10 @@ jobs: | |
with: | ||
toolchain: ${{ matrix.rust }} | ||
- uses: Swatinem/rust-cache@v2 | ||
- name: Configure git | ||
run: | | ||
git config --global user.name "Test User" | ||
git config --global user.email "[email protected]" | ||
- uses: taiki-e/install-action@cargo-hack | ||
- name: Build | ||
run: cargo test --workspace --no-run | ||
|
@@ -52,6 +56,10 @@ jobs: | |
with: | ||
toolchain: stable | ||
- uses: Swatinem/rust-cache@v2 | ||
- name: Configure git | ||
run: | | ||
git config --global user.name "Test User" | ||
git config --global user.email "[email protected]" | ||
- uses: taiki-e/install-action@cargo-hack | ||
- name: Update dependencies | ||
run: cargo update | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,138 @@ | ||
use snapbox::str; | ||
|
||
#[test] | ||
fn wip() { | ||
fn has_message_fails() { | ||
run_committed("", "") | ||
.code(1) | ||
.stdout_eq(str![[r#" | ||
-: error Empty commits are disallowed | ||
"#]]) | ||
.stderr_eq(str![]); | ||
} | ||
|
||
#[test] | ||
fn wip_fails() { | ||
run_committed("wip bad times ahead", "") | ||
.code(1) | ||
.stdout_eq(str![[r#" | ||
-: error Work-in-progress commits must be cleaned up | ||
"#]]) | ||
.stderr_eq(str![]); | ||
} | ||
|
||
#[test] | ||
fn wip_config_override() { | ||
run_committed("wip bad times ahead", "no_wip = false") | ||
.code(1) | ||
.stdout_eq(str![[r#" | ||
-: error Subject should be capitalized but found `bad` | ||
"#]]) | ||
.stderr_eq(str![]); | ||
} | ||
|
||
#[test] | ||
fn wip_stops_checks() { | ||
run_committed("wip bad times", "") | ||
.code(1) | ||
.stdout_eq(str![[r#" | ||
-: error Work-in-progress commits must be cleaned up | ||
"#]]) | ||
.stderr_eq(str![]); | ||
} | ||
|
||
#[test] | ||
fn fixup_fails() { | ||
run_committed("fixup! bad times ahead", "") | ||
.code(1) | ||
.stdout_eq(str![[r#" | ||
-: error Fixup commits must be squashed | ||
"#]]) | ||
.stderr_eq(str![]); | ||
} | ||
|
||
#[test] | ||
fn fixup_config_override() { | ||
run_committed("fixup! bad times ahead", "no_fixup = false") | ||
.code(1) | ||
.stdout_eq(str![[r#" | ||
-: error Subject should be capitalized but found `bad` | ||
"#]]) | ||
.stderr_eq(str![]); | ||
} | ||
|
||
#[test] | ||
fn fixup_stops_checks() { | ||
run_committed("fixup! bad times", "") | ||
.code(1) | ||
.stdout_eq(str![[r#" | ||
-: error Fixup commits must be squashed | ||
"#]]) | ||
.stderr_eq(str![]); | ||
} | ||
|
||
#[track_caller] | ||
fn run_committed(message: &str, config: &str) -> snapbox::cmd::OutputAssert { | ||
let root = snapbox::dir::DirRoot::mutable_temp().unwrap(); | ||
let root_dir = root.path().unwrap(); | ||
std::fs::write(root_dir.join("committed.toml"), "").unwrap(); | ||
|
||
git2::Repository::init(root_dir).unwrap(); | ||
let config_path = root_dir.join("committed.toml"); | ||
std::fs::write(&config_path, config).unwrap(); | ||
|
||
let message = "WIP: bad times ahead"; | ||
snapbox::cmd::Command::new(snapbox::cmd::cargo_bin!("committed")) | ||
let assert = snapbox::cmd::Command::new(snapbox::cmd::cargo_bin!("committed")) | ||
.arg("--commit-file=-") | ||
.arg("--config") | ||
.arg(&config_path) | ||
.current_dir(root_dir) | ||
.stdin(message) | ||
.assert() | ||
.assert(); | ||
|
||
root.close().unwrap(); | ||
|
||
assert | ||
} | ||
|
||
#[test] | ||
fn in_repo() { | ||
run_committed_repo("WIP: bad times ahead", "") | ||
.code(1) | ||
.stdout_eq(str![[r#" | ||
-: error Work-in-progress commits must be cleaned up | ||
[..]: error Work-in-progress commits must be cleaned up | ||
"#]]) | ||
.stderr_eq(str![]); | ||
} | ||
|
||
fn run_committed_repo(message: &str, config: &str) -> snapbox::cmd::OutputAssert { | ||
let root = snapbox::dir::DirRoot::mutable_temp().unwrap(); | ||
let root_dir = root.path().unwrap(); | ||
let config_filename = "committed.toml"; | ||
let config_path = root_dir.join(config_filename); | ||
std::fs::write(&config_path, config).unwrap(); | ||
|
||
let repo = git2::Repository::init(root_dir).unwrap(); | ||
let mut index = repo.index().unwrap(); | ||
index | ||
.add_path(std::path::Path::new(config_filename)) | ||
.unwrap(); | ||
index.write().unwrap(); | ||
let id = index.write_tree().unwrap(); | ||
let tree = repo.find_tree(id).unwrap(); | ||
let sig = repo.signature().unwrap(); | ||
repo.commit(Some("HEAD"), &sig, &sig, message, &tree, &[]) | ||
.unwrap(); | ||
|
||
let assert = snapbox::cmd::Command::new(snapbox::cmd::cargo_bin!("committed")) | ||
.arg("HEAD") | ||
.current_dir(root_dir) | ||
.assert(); | ||
|
||
root.close().unwrap(); | ||
|
||
assert | ||
} |