How to force git to warn or add new files?

622 views Asked by At

We've all experienced that painful moment when a new feature works fine locally but breaks when deployed because we forgot to add a new file.

Is there a way to make git warn or automatically add new files when git commit -a is executed?

2

There are 2 answers

0
pielgrzym On

A pre-commit hook like this should alarm about leftover files:

#!/bin/bash
. git-sh-setup # for 'die' cmd
git status --porcelain | while IFS= read -r line;
do
         if [[ $line == \?\?* ]] ; then # if the file begins with ?? it's untracked by git
                die "Uncommited files left!" # this will always terminate commit
                # say "Uncommited files left!" # this will just print the warning
         fi
done

Just add this to your repo's pre-commit hooks and voile :)

EDIT: you should also consider using some continuous integration toolkit like Hudson or Buildbot - it can perform a lot more comprehensive check then looking for missing files :)

EDIT2: unfortunately I didn't succeed in using read inside the loop so I think it might not be possible to make this hook ask for your action.

0
Fatih Arslan On
git config --global alias.commita '!git add . && git commit -a'

After that just use:

git commita ..

instad of git commit -a. That will add new files too.