Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
j178 committed Dec 3, 2024
1 parent 897d8fe commit 6b7bc87
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 56 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/build-binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ jobs:
set -euo pipefail
TARGET=${{ matrix.platform.target }}
ARCHIVE_NAME=pre-commit-rs-$TARGET
ARCHIVE_NAME=prefligit-$TARGET
ARCHIVE_FILE=$ARCHIVE_NAME.tar.gz
mkdir -p $ARCHIVE_NAME
cp target/$TARGET/release/pre-commit $ARCHIVE_NAME/pre-commit
cp target/$TARGET/release/prefligit $ARCHIVE_NAME/prefligit
tar czvf $ARCHIVE_FILE $ARCHIVE_NAME
shasum -a 256 $ARCHIVE_FILE > $ARCHIVE_FILE.sha256
- name: "Upload binary"
Expand Down Expand Up @@ -92,8 +92,8 @@ jobs:
- name: "Archive binary"
shell: bash
run: |
ARCHIVE_FILE=pre-commit-rs-${{ matrix.platform.target }}.zip
7z a $ARCHIVE_FILE ./target/${{ matrix.platform.target }}/release/pre-commit.exe
ARCHIVE_FILE=prefligit-${{ matrix.platform.target }}.zip
7z a $ARCHIVE_FILE ./target/${{ matrix.platform.target }}/release/prefligit.exe
sha256sum $ARCHIVE_FILE > $ARCHIVE_FILE.sha256
- name: "Upload binary"
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -128,11 +128,11 @@ jobs:
- name: "Archive binary"
run: |
TARGET=${{ matrix.platform.target }}
ARCHIVE_NAME=pre-commit-rs-$TARGET
ARCHIVE_NAME=prefligit-$TARGET
ARCHIVE_FILE=$ARCHIVE_NAME.tar.gz
mkdir -p $ARCHIVE_NAME
cp target/$TARGET/release/pre-commit $ARCHIVE_NAME/pre-commit
cp target/$TARGET/release/prefligit $ARCHIVE_NAME/prefligit
tar czvf $ARCHIVE_FILE $ARCHIVE_NAME
shasum -a 256 $ARCHIVE_FILE > $ARCHIVE_FILE.sha256
- name: "Upload binary"
Expand Down
6 changes: 1 addition & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ license-file = "LICENSE"
# `cargo publish` failed because of this, disabled for now.
# include = ["licenses/.*"]

[[bin]]
path = "src/main.rs"
name = "prefligit"

[features]
default = ["docker"]
profiler = ["dep:pprof", "profiler-flamegraph"]
Expand Down Expand Up @@ -143,7 +139,7 @@ publish-jobs = ["./publish", "homebrew"]
# A GitHub repo to push Homebrew formulas to
tap = "j178/homebrew-tap"
# Customize the Homebrew formula name
formula = "pre-commit-rs"
formula = "prefligit"
# Whether to install an updater program
install-updater = false
# Path that installers should place binaries in
Expand Down
2 changes: 1 addition & 1 deletion src/cli/hook_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub(crate) async fn hook_impl(
"- To temporarily silence this, run `PRE_COMMIT_ALLOW_NO_CONFIG=1 git ...`"
);
eprintln!("- To permanently silence this, install hooks with the `--allow-missing-config` flag");
eprintln!("- To uninstall hooks, run `pre-commit uninstall`");
eprintln!("- To uninstall hooks, run `prefligit uninstall`");
Ok(ExitStatus::Failure)
};
}
Expand Down
18 changes: 9 additions & 9 deletions src/cli/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,13 @@ fn install_hook_script(
args.push("--skip-on-missing-config".to_string());
}

let pre_commit = std::env::current_exe()?;
let pre_commit = pre_commit.simplified().display().to_string();
let prefligit = std::env::current_exe()?;
let pre_commit = prefligit.simplified().display().to_string();
let hook_script = HOOK_TMPL
.replace("ARGS=(hook-impl)", &format!("ARGS=({})", args.join(" ")))
.replace(
r#"PRE_COMMIT="pre-commit""#,
&format!(r#"PRE_COMMIT="{pre_commit}""#),
r#"PREFLIGIT="prefligit""#,
&format!(r#"PREFLIGIT="{pre_commit}""#),
);
fs_err::OpenOptions::new()
.write(true)
Expand All @@ -162,7 +162,7 @@ fn install_hook_script(

writeln!(
printer.stdout(),
"pre-commit installed at {}",
"prefligit installed at {}",
hook_path.user_display().cyan()
)?;

Expand All @@ -178,9 +178,9 @@ ARGS=(hook-impl)
HERE="$(cd "$(dirname "$0")" && pwd)"
ARGS+=(--hook-dir "$HERE" -- "$@")
PRE_COMMIT="pre-commit"
PREFLIGIT="prefligit"
exec "$PRE_COMMIT" "${ARGS[@]}"
exec "$PREFLIGIT" "${ARGS[@]}"
"# };

Expand All @@ -190,7 +190,7 @@ static PRIOR_HASHES: &[&str] = &[];
// Use a different hash from `pre-commit` since our script is different.
static CURRENT_HASH: &str = "182c10f181da4464a3eec51b83331688";

/// Checks if the script contains any of the hashes that `pre-commit` has used in the past.
/// Checks if the script contains any of the hashes that `prefligit` has used in the past.
fn is_our_script(hook_path: &Path) -> Result<bool> {
let content = fs_err::read_to_string(hook_path)?;
Ok(std::iter::once(CURRENT_HASH)
Expand All @@ -217,7 +217,7 @@ pub(crate) async fn uninstall(
} else if !is_our_script(&hook_path)? {
writeln!(
printer.stderr(),
"{} is not managed by pre-commit, skipping.",
"{} is not managed by prefligit, skipping.",
hook_path.user_display().cyan()
)?;
} else {
Expand Down
8 changes: 4 additions & 4 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl From<ColorChoice> for anstream::ColorChoice {

#[derive(Parser)]
#[command(
name = "pre-commit",
name = "prefligit",
author,
version,
about = "pre-commit reimplemented in Rust"
Expand Down Expand Up @@ -135,7 +135,7 @@ pub(crate) struct GlobalArgs {
#[arg(global = true, short, long, action = ArgAction::Count)]
pub(crate) verbose: u8,

/// Display the pre-commit version.
/// Display the prefligit version.
#[arg(global = true, short = 'V', long, action = clap::ArgAction::Version)]
version: Option<bool>,

Expand All @@ -148,14 +148,14 @@ pub(crate) struct GlobalArgs {

#[derive(Debug, Subcommand)]
pub(crate) enum Command {
/// Install the git pre-commit hook.
/// Install the git prefligit hook.
#[command(name = "install")]
Install(InstallArgs),
/// Create hook environments for all hooks used in the config file.
InstallHooks,
/// Run hooks.
Run(Box<RunArgs>),
/// Uninstall the pre-commit script.
/// Uninstall the prefligit script.
Uninstall(UninstallArgs),
/// Validate `.pre-commit-config.yaml` files.
ValidateConfig(ValidateConfigArgs),
Expand Down
2 changes: 1 addition & 1 deletion src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub(crate) async fn run(
if should_stash && git::has_unmerged_paths().await? {
writeln!(
printer.stderr(),
"You have unmerged paths. Resolve them before running pre-commit."
"You have unmerged paths. Resolve them before running prefligit."
)?;
return Ok(ExitStatus::Failure);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
cli.command = Some(Command::Run(Box::new(cli.run_args.clone())));
}

debug!("pre-commit: {}", env!("CARGO_PKG_VERSION"));
debug!("prefligit: {}", env!("CARGO_PKG_VERSION"));

match get_root().await {
Ok(root) => {
Expand Down
8 changes: 4 additions & 4 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl TestContext {
.map(|pattern| (pattern, "[HOME]/".to_string())),
);

let current_exe = assert_cmd::cargo::cargo_bin("pre-commit");
let current_exe = assert_cmd::cargo::cargo_bin("prefligit");
filters.extend(
Self::path_patterns(&current_exe)
.into_iter()
Expand Down Expand Up @@ -112,7 +112,7 @@ impl TestContext {
}

pub fn command(&self) -> Command {
let bin = assert_cmd::cargo::cargo_bin("pre-commit");
let bin = assert_cmd::cargo::cargo_bin("prefligit");
let mut cmd = Command::new(bin);
cmd.current_dir(self.workdir());
cmd.env("PRE_COMMIT_HOME", &*self.home_dir);
Expand Down Expand Up @@ -177,7 +177,7 @@ impl TestContext {
&self.temp_dir
}

/// Initialize a sample project for pre-commit.
/// Initialize a sample project for prefligit.
pub fn init_project(&self) {
Command::new("git")
.arg("init")
Expand Down Expand Up @@ -241,7 +241,7 @@ pub const INSTA_FILTERS: &[(&str, &str)] = &[
(r"(\s|\()(\d+\.)?\d+([KM]i)?B", "$1[SIZE]"),
// Rewrite Windows output to Unix output
(r"\\([\w\d]|\.\.)", "/$1"),
(r"pre-commit.exe", "pre-commit"),
(r"prefligit.exe", "prefligit"),
// The exact message is host language dependent
(
r"Caused by: .* \(os error 2\)",
Expand Down
2 changes: 1 addition & 1 deletion tests/hook_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn hook_impl() {
success: true
exit_code: 0
----- stdout -----
pre-commit installed at .git/hooks/pre-commit
prefligit installed at .git/hooks/pre-commit
----- stderr -----
"#);
Expand Down
41 changes: 18 additions & 23 deletions tests/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ fn install() -> anyhow::Result<()> {
let context = TestContext::new();
context.init_project();

// Install `pre-commit` hook.
// Install `prefligit` hook.
cmd_snapshot!(context.filters(), context.install(), @r#"
success: true
exit_code: 0
----- stdout -----
pre-commit installed at .git/hooks/pre-commit
prefligit installed at .git/hooks/pre-commit
----- stderr -----
"#);
Expand All @@ -35,10 +35,9 @@ fn install() -> anyhow::Result<()> {
HERE="$(cd "$(dirname "$0")" && pwd)"
ARGS+=(--hook-dir "$HERE" -- "$@")
PRE_COMMIT="[CURRENT_EXE]"
exec "$PRE_COMMIT" "${ARGS[@]}"
PREFLIGIT="[CURRENT_EXE]"
exec "$PREFLIGIT" "${ARGS[@]}"
"##);
}
);
Expand All @@ -54,8 +53,8 @@ fn install() -> anyhow::Result<()> {
exit_code: 0
----- stdout -----
Hook already exists at .git/hooks/pre-commit, move it to .git/hooks/pre-commit.legacy.
pre-commit installed at .git/hooks/pre-commit
pre-commit installed at .git/hooks/post-commit
prefligit installed at .git/hooks/pre-commit
prefligit installed at .git/hooks/post-commit
----- stderr -----
"#);
Expand All @@ -71,10 +70,9 @@ fn install() -> anyhow::Result<()> {
HERE="$(cd "$(dirname "$0")" && pwd)"
ARGS+=(--hook-dir "$HERE" -- "$@")
PRE_COMMIT="[CURRENT_EXE]"
exec "$PRE_COMMIT" "${ARGS[@]}"
PREFLIGIT="[CURRENT_EXE]"
exec "$PREFLIGIT" "${ARGS[@]}"
"##);
}
);
Expand All @@ -96,10 +94,9 @@ fn install() -> anyhow::Result<()> {
HERE="$(cd "$(dirname "$0")" && pwd)"
ARGS+=(--hook-dir "$HERE" -- "$@")
PRE_COMMIT="[CURRENT_EXE]"
exec "$PRE_COMMIT" "${ARGS[@]}"
PREFLIGIT="[CURRENT_EXE]"
exec "$PREFLIGIT" "${ARGS[@]}"
"##);
}
);
Expand All @@ -110,9 +107,9 @@ fn install() -> anyhow::Result<()> {
exit_code: 0
----- stdout -----
Overwriting existing hook at .git/hooks/pre-commit
pre-commit installed at .git/hooks/pre-commit
prefligit installed at .git/hooks/pre-commit
Overwriting existing hook at .git/hooks/post-commit
pre-commit installed at .git/hooks/post-commit
prefligit installed at .git/hooks/post-commit
----- stderr -----
"#);
Expand All @@ -129,10 +126,9 @@ fn install() -> anyhow::Result<()> {
HERE="$(cd "$(dirname "$0")" && pwd)"
ARGS+=(--hook-dir "$HERE" -- "$@")
PRE_COMMIT="[CURRENT_EXE]"
exec "$PRE_COMMIT" "${ARGS[@]}"
PREFLIGIT="[CURRENT_EXE]"
exec "$PREFLIGIT" "${ARGS[@]}"
"##);
}
);
Expand All @@ -148,10 +144,9 @@ fn install() -> anyhow::Result<()> {
HERE="$(cd "$(dirname "$0")" && pwd)"
ARGS+=(--hook-dir "$HERE" -- "$@")
PRE_COMMIT="[CURRENT_EXE]"
exec "$PRE_COMMIT" "${ARGS[@]}"
PREFLIGIT="[CURRENT_EXE]"
exec "$PREFLIGIT" "${ARGS[@]}"
"##);
}
);
Expand Down Expand Up @@ -201,7 +196,7 @@ fn uninstall() -> anyhow::Result<()> {
----- stdout -----
----- stderr -----
.git/hooks/pre-commit is not managed by pre-commit, skipping.
.git/hooks/pre-commit is not managed by prefligit, skipping.
"#);

// Restore previous hook.
Expand Down Expand Up @@ -248,7 +243,7 @@ fn init_template_dir() {
success: true
exit_code: 0
----- stdout -----
pre-commit installed at .git/hooks/pre-commit
prefligit installed at .git/hooks/pre-commit
----- stderr -----
`init.templateDir` not set to the target directory
Expand Down
2 changes: 1 addition & 1 deletion tests/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ fn merge_conflicts() -> Result<()> {
----- stdout -----
----- stderr -----
You have unmerged paths. Resolve them before running pre-commit.
You have unmerged paths. Resolve them before running prefligit.
"#);

// Fix the conflict and run again.
Expand Down

0 comments on commit 6b7bc87

Please sign in to comment.