Pre-commit Hook
Opened this issue · 5 comments
Would it be possible to add a pre-commit hook? Specifically - I'm looking at using it to automatically write vcsh gitignore files and simplify this workflow. Right now there are a bunch of steps:
- Write the first gitignore file
vcsh write-gitignore <repo_name>
- Add the gitignore file to the gitignore file.
- Add & commit the gitignore file.
- Push the refs.
When adding a new file, you either need to manually edit the gitignore file to include the new file you want to commit, or commit the file using the -f
flag, rerun vcsh write-gitignore <repo>
, and then re-add the gitignore file to the gitignore file.
Instead, I'd like to just add a pre-commit hook (except it doesn't exist) to:
- Write and add the gitignore file if it doesn't already exist, including files from the work-tree.
- Add the file being commited to the gitignore file if it doesn't already exist.
Why are you adding the gitginore file to the ignore list? I agree that a hook would be nice to keep the ignores up to date since I do it every time anyway but it seems like you have one step too many in here.
@alerque Sorry, you're correct. When re-running vcsh write-gitignore <name>
the /.gitignore.d/<repo_name>
file is automatically rewritten with itself included and does not need to be re-added.
I can add a hook before git commit --untracked-files=no --quiet
in commit()
if you need me to, but it seems you don't need that any more?
@alerque is correct that you don't need to re-add the gitignore file each time you regenerate the gitignore file (you do have to add it initially).
That was tangential to the main point though: It would be nice to have have a way (through hooks) that could be used to rewrite the vcsh repo gitignore file each time a new file is commited to the repo (i think on commit would be more appropriate then when staged, since, since a staged file may be removed, leaving files that were never commited in the ignore file).
To do this, I'd just need a pre-commit hook, so I can enumerate the files in the work tree, compare them against the files in ignore file, and if they differ, execute vcsh write-gitignore $ VCSH_REPO_NAME
.