Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pre-commit Hook #178

Open
nfarrar opened this issue Aug 18, 2015 · 5 comments
Open

Pre-commit Hook #178

nfarrar opened this issue Aug 18, 2015 · 5 comments
Labels

Comments

@nfarrar
Copy link

nfarrar commented Aug 18, 2015

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
Copy link
Collaborator

alerque commented Aug 18, 2015

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
Copy link
Author

nfarrar commented Aug 18, 2015

@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
Copy link
Owner

RichiH commented Nov 29, 2015

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
Copy link
Author

nfarrar commented Nov 29, 2015

@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
Copy link
Owner

RichiH commented Nov 29, 2015

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants