RichiH / vcsh

config manager based on Git
GNU General Public License v2.0
2.19k stars 122 forks source link

Pre-commit Hook #178

Open nfarrar opened 9 years ago

nfarrar commented 9 years ago

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:

  1. Write the first gitignore file vcsh write-gitignore <repo_name>
  2. Add the gitignore file to the gitignore file.
  3. Add & commit the gitignore file.
  4. 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:

  1. Write and add the gitignore file if it doesn't already exist, including files from the work-tree.
  2. Add the file being commited to the gitignore file if it doesn't already exist.
alerque commented 9 years ago

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.

nfarrar commented 9 years ago

@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.

RichiH commented 8 years ago

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?

nfarrar commented 8 years ago

@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.

RichiH commented 8 years ago

@nfarrar did you play with the existing pre-commit hook?