diff options
author | Michael Gattozzi <mgattozzi@gmail.com> | 2019-11-22 09:52:39 -0500 |
---|---|---|
committer | Michael Gattozzi <mgattozzi@gmail.com> | 2019-11-22 09:52:39 -0500 |
commit | b966334bf8c67cc82999d8b0962db15c8121bab7 (patch) | |
tree | b74272358b7cffd4749905b02b16802dd95284af | |
parent | 2cd27b8dd40c7361f6f2b8832e210a58f30f3639 (diff) |
Add hooked and empty inited hooks from the tool
This adds the hooked binary to the dev-suite repo as well as a stub for
a program to be used in this workflow! Hooked works by adding the hooks
into the repo and setting them to executable and linking them into the
hooks directory under .git. This means hooks get to travel with the
repo and are source controlled. All a dev needs to do is run the init
command and hooked will symlink them all for them. No need to remember
how ln works. It's all handled for you. Future work will iterate about
what hooks that dev-suite supplies as part of the script. This will
involve configuration files and per repo settings are something that
will need to be thought about.
Closes Issue #2
24 files changed, 131 insertions, 1 deletions
diff --git a/.dev-suite/hooked/applypatch-msg b/.dev-suite/hooked/applypatch-msg new file mode 100755 index 0000000..efcbaec --- /dev/null +++ b/.dev-suite/hooked/applypatch-msg @@ -0,0 +1 @@ +#! /bin/bash
\ No newline at end of file diff --git a/.dev-suite/hooked/commit-msg b/.dev-suite/hooked/commit-msg new file mode 100755 index 0000000..efcbaec --- /dev/null +++ b/.dev-suite/hooked/commit-msg @@ -0,0 +1 @@ +#! /bin/bash
\ No newline at end of file diff --git a/.dev-suite/hooked/post-applypatch b/.dev-suite/hooked/post-applypatch new file mode 100755 index 0000000..efcbaec --- /dev/null +++ b/.dev-suite/hooked/post-applypatch @@ -0,0 +1 @@ +#! /bin/bash
\ No newline at end of file diff --git a/.dev-suite/hooked/post-checkout b/.dev-suite/hooked/post-checkout new file mode 100755 index 0000000..efcbaec --- /dev/null +++ b/.dev-suite/hooked/post-checkout @@ -0,0 +1 @@ +#! /bin/bash
\ No newline at end of file diff --git a/.dev-suite/hooked/post-commit b/.dev-suite/hooked/post-commit new file mode 100755 index 0000000..efcbaec --- /dev/null +++ b/.dev-suite/hooked/post-commit @@ -0,0 +1 @@ +#! /bin/bash
\ No newline at end of file diff --git a/.dev-suite/hooked/post-merge b/.dev-suite/hooked/post-merge new file mode 100755 index 0000000..efcbaec --- /dev/null +++ b/.dev-suite/hooked/post-merge @@ -0,0 +1 @@ +#! /bin/bash
\ No newline at end of file diff --git a/.dev-suite/hooked/post-receive b/.dev-suite/hooked/post-receive new file mode 100755 index 0000000..efcbaec --- /dev/null +++ b/.dev-suite/hooked/post-receive @@ -0,0 +1 @@ +#! /bin/bash
\ No newline at end of file diff --git a/.dev-suite/hooked/post-rewrite b/.dev-suite/hooked/post-rewrite new file mode 100755 index 0000000..efcbaec --- /dev/null +++ b/.dev-suite/hooked/post-rewrite @@ -0,0 +1 @@ +#! /bin/bash
\ No newline at end of file diff --git a/.dev-suite/hooked/post-update b/.dev-suite/hooked/post-update new file mode 100755 index 0000000..efcbaec --- /dev/null +++ b/.dev-suite/hooked/post-update @@ -0,0 +1 @@ +#! /bin/bash
\ No newline at end of file diff --git a/.dev-suite/hooked/pre-auto-gc b/.dev-suite/hooked/pre-auto-gc new file mode 100755 index 0000000..efcbaec --- /dev/null +++ b/.dev-suite/hooked/pre-auto-gc @@ -0,0 +1 @@ +#! /bin/bash
\ No newline at end of file diff --git a/.dev-suite/hooked/pre-commit b/.dev-suite/hooked/pre-commit new file mode 100755 index 0000000..efcbaec --- /dev/null +++ b/.dev-suite/hooked/pre-commit @@ -0,0 +1 @@ +#! /bin/bash
\ No newline at end of file diff --git a/.dev-suite/hooked/pre-push b/.dev-suite/hooked/pre-push new file mode 100755 index 0000000..efcbaec --- /dev/null +++ b/.dev-suite/hooked/pre-push @@ -0,0 +1 @@ +#! /bin/bash
\ No newline at end of file diff --git a/.dev-suite/hooked/pre-rebase b/.dev-suite/hooked/pre-rebase new file mode 100755 index 0000000..efcbaec --- /dev/null +++ b/.dev-suite/hooked/pre-rebase @@ -0,0 +1 @@ +#! /bin/bash
\ No newline at end of file diff --git a/.dev-suite/hooked/pre-receive b/.dev-suite/hooked/pre-receive new file mode 100755 index 0000000..efcbaec --- /dev/null +++ b/.dev-suite/hooked/pre-receive @@ -0,0 +1 @@ +#! /bin/bash
\ No newline at end of file diff --git a/.dev-suite/hooked/prepare-commit-msg b/.dev-suite/hooked/prepare-commit-msg new file mode 100755 index 0000000..efcbaec --- /dev/null +++ b/.dev-suite/hooked/prepare-commit-msg @@ -0,0 +1 @@ +#! /bin/bash
\ No newline at end of file diff --git a/.dev-suite/hooked/push-to-checkout b/.dev-suite/hooked/push-to-checkout new file mode 100755 index 0000000..efcbaec --- /dev/null +++ b/.dev-suite/hooked/push-to-checkout @@ -0,0 +1 @@ +#! /bin/bash
\ No newline at end of file diff --git a/.dev-suite/hooked/sendemail-validate b/.dev-suite/hooked/sendemail-validate new file mode 100755 index 0000000..efcbaec --- /dev/null +++ b/.dev-suite/hooked/sendemail-validate @@ -0,0 +1 @@ +#! /bin/bash
\ No newline at end of file diff --git a/.dev-suite/hooked/update b/.dev-suite/hooked/update new file mode 100755 index 0000000..efcbaec --- /dev/null +++ b/.dev-suite/hooked/update @@ -0,0 +1 @@ +#! /bin/bash
\ No newline at end of file diff --git a/.dev-suite/ticket/open/2-create-git-hooks-tool.toml b/.dev-suite/ticket/closed/2-create-git-hooks-tool.toml index 19d8904..c51799c 100644 --- a/.dev-suite/ticket/open/2-create-git-hooks-tool.toml +++ b/.dev-suite/ticket/closed/2-create-git-hooks-tool.toml @@ -1,5 +1,5 @@ title = 'Create git hooks tool' -status = 'Open' +status = 'Closed' number = 2 description = ''' Git hooks are great, but the problem is that it's hard to standardize @@ -190,6 +190,16 @@ dependencies = [ ] [[package]] +name = "hooked" +version = "0.1.0" +dependencies = [ + "anyhow 1.0.22 (registry+https://github.com/rust-lang/crates.io-index)", + "paw 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "shared 0.1.0", + "structopt 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2,4 +2,5 @@ members = [ "shared", "ticket", + "hooked", ] diff --git a/hooked/Cargo.toml b/hooked/Cargo.toml new file mode 100644 index 0000000..acde074 --- /dev/null +++ b/hooked/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "hooked" +version = "0.1.0" +authors = ["Michael Gattozzi <mgattozzi@gmail.com>"] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +anyhow = "1.0" +paw = "1.0" +shared = { path = "../shared" } +structopt = { version = "0.3", features = ["paw"] } diff --git a/hooked/src/bin/hooked-commit-msg.rs b/hooked/src/bin/hooked-commit-msg.rs new file mode 100644 index 0000000..80a1832 --- /dev/null +++ b/hooked/src/bin/hooked-commit-msg.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/hooked/src/main.rs b/hooked/src/main.rs new file mode 100644 index 0000000..d412469 --- /dev/null +++ b/hooked/src/main.rs @@ -0,0 +1,85 @@ +#[cfg(windows)] +use anyhow::bail; +use anyhow::Result; +use shared::find_root; +#[cfg(not(windows))] +use std::os::unix::fs::{ + symlink, + PermissionsExt, +}; +#[cfg(windows)] +use std::os::windows::fs::symlink_file; +use std::{ + fs, + io::Write, +}; + +const HOOKS: [&str; 18] = [ + "applypatch-msg", + "post-applypatch", + "pre-commit", + "prepare-commit-msg", + "commit-msg", + "post-commit", + "pre-rebase", + "post-checkout", + "post-merge", + "pre-push", + "pre-receive", + "update", + "post-receive", + "post-update", + "push-to-checkout", + "pre-auto-gc", + "post-rewrite", + "sendemail-validate", +]; + +#[derive(structopt::StructOpt)] +enum Args { + /// Initialize the repo to use ticket + Init, +} + +#[paw::main] +fn main(args: Args) { + if let Err(e) = match args { + Args::Init => init(), + } { + eprintln!("{}", e); + std::process::exit(1); + } +} + +fn init() -> Result<()> { + #[cfg(windows)] + bail!("Windows is currently unsupported!"); + + let root = find_root()?; + let git_hooks = &root.join(".git").join("hooks"); + let root = root.join(".dev-suite").join("hooked"); + fs::create_dir_all(&root)?; + + for hook in &HOOKS { + let path = &root.join(hook); + let git_hook = &git_hooks.join(hook); + + if !path.exists() { + let mut file = fs::File::create(&path)?; + let mut perms = file.metadata()?.permissions(); + perms.set_mode(0o755); + file.set_permissions(perms)?; + file.write_all(b"#! /bin/bash")?; + } + let path = path.canonicalize()?; + + if !git_hook.exists() { + #[cfg(not(windows))] + symlink(&path, &git_hook)?; + #[cfg(windows)] + symlink_file(&path, &git_hook)?; + } + } + + Ok(()) +} |