Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using git hook to add license and app version to comment at top of source files

Tags:

git

hook

I am trying to create a pre-commit hook for git that edits the comments at the top of each of my .h and .m files. I would like to change the header comments added by x-code to include the app version and license information. This would be helpful when changing to a new version.

This is the text that is automatically inserted when I create a file in x-code:

//
//  myFile.h
//  myApp 
//
//  Created by Developer on 11/13/12.
//  Copyright (c) 2012 myCompany LLC. All rights reserved.
//

I would like the hook to change it to this:

/*

myFile.h
myApp
Version: 1.0

myApp is free software: you can redistribute it and/or modify it under the terms 
of the GNU General Public License as published by the Free Software Foundation,
either version 2 of the License, or (at your option) any later version.

myApp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
PURPOSE.  See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with myApp.
If not, see <http://www.gnu.org/licenses/>

Copyright 2012 myCompany. All rights reserved.


This notice may not be removed from this file.

*/

I was thinking that I would have a text file with the header text I want to change. Or detect when the app version number changes. When this file is updated with a new version number and git I do a git commit, then it will update all the other files with the new version and change any new files to have the correct header text. This seems like it might be useful.

like image 894
Bryan Aneux Avatar asked Jan 19 '13 22:01

Bryan Aneux


People also ask

How do I add a git hook?

To install the hook, you can either create a symlink to it in . git/hooks , or you can simply copy and paste it into the . git/hooks directory whenever the hook is updated. As an alternative, Git also provides a Template Directory mechanism that makes it easier to install hooks automatically.

How do I make a git hook executable?

Open a terminal window by using option + T in GitKraken Client. Once the terminal windows is open, change directory to . git/hooks . Then use the command chmod +x pre-commit to make the pre-commit file executable.

How do you run pre-commit on all files?

If you want to manually run all pre-commit hooks on a repository, run pre-commit run --all-files . To run individual hooks use pre-commit run <hook_id> . The first time pre-commit runs on a file it will automatically download, install, and run the hook.

What is git hooks How do you use them?

Git hooks are shell scripts found in the hidden . git/hooks directory of a Git repository. These scripts trigger actions in response to specific events, so they can help you automate your development lifecycle. Although you may never have noticed them, every Git repository includes 12 sample scripts.


1 Answers

Use smudge/clean filters (full chapter, linked "Keyword Expansion" most carefully)?

like image 115
Lazy Badger Avatar answered Nov 05 '22 07:11

Lazy Badger