V
V
Valery Selitsky2013-03-11 12:26:36
linux
Valery Selitsky, 2013-03-11 12:26:36

Crunchy automation in production: git add doesn't work in pre-receive hook

There is a git repository ( not bare ) on production, the task is to maximize the automation of source synchronization on developers' machines with production.
As part of the task, I developed a solution:

  1. To pre-receiveadd changes from the working copy on the production server to the repository and commit, because SEO specialists and other departments also have access to upload and delete their files
  2. On post-receiveforcibly upload the contents of the repository to production, usinggit-checkout -f
So, the second item has been working for a long time and successfully, but there were problems with the first one, and they are expressed in the fact that when you try to add files in the working directory git add ., the command gives an error adding a file.git/COMMIT_EDITMSG
error: unable to add .git/COMMIT_EDITMSG to index
fatal: adding files failed
Why gitit is trying to add files from its directory remains a mystery to me ...

I have in my head a variant of implementing this workflow bypassing the addition of all files - parse the output git status, processing the corresponding changes with git addand git rm, but it seems to me that the problem is somewhere higher and on the surface and I don't have enough experience.

If I am architecturally wrong in some way and everything can be organized differently, I will carefully listen to your implementation option.
It is worth adding that we have this machine admin-managed, so I don’t have root rights, and, accordingly, I don’t have rights to cron.

I am attaching the contents of the hook pre-receive:
#!/bin/sh

#### указываем рабочие папки
export GIT_WORK_TREE=/workingpath
export GIT_DIR=/workingpath/.git
#### добавляем новые изменения
git add .
#### обновляем модификации
git add -u .
#### фиксируем
git commit -a -m 'Sync on remote PUSH'
#### на время тестирования фэйлим все коммиты
exit 1


git version 1.5.6.5

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question