简体   繁体   中英

run a script in a project from a git command

I want to validate branch names when someone on my team does: git checkout -b [branch-name and then do some validation and give them feedback if they don't hit the criteria

I don't seem to be able to create custom hooks and im not sure how to create a script that runs when someone types git checkout -b . can someone give me a clue how to do this?

also once I commit this PR into master I would like the command git checkout -b to work on other peoples machines as soon as they pull this new code down

What you've described is that you want to commit something into a repo, so that if someone pull s from that repo, the behavior of a common git command is changed so as to run arbitrary code of your choosing. This is not something git supports, and hopefully it never will (as doing so would be a huge security hole).

I don't seem to be able to create custom hooks

Why is that?

I ask because hooks are the closest thing you're going to get to what you want. In particular, you should enforce branch naming (or any other conventions) on the remote using a pre-receive hook (and give up on caring what branch names might be used locally by the devs).

If your developers want something client-side so that they can "fail fast" when they make errors with respect to this naming convention - and once you have server-side enforcement, they probably will - then you can offer them the same underlying script to run as needed. They can then set it up locally in whatever way they see fit - perhaps as an alias, for example.

If you can't use a pre-receive hook - eg if the software that hosts your remote doesn't provide for custom hooks - then git has no direct support that's likely to help. In the case that server software is getting in the way, consult that software's docs to see what functionality it might offer in lieu of hooks.

In the end, you may not be able to rely on the software to enforce your naming policy. Not everything is best solved as a technical problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM