doubt

Is possible change owner directories and files when I use command git pull?

Why I try add script with name post-merge on directory hooks, but when I execute command git pull, don’t execute my scripts. Any idea? I look inumerals howtoo.

I’m not entirely sure what it is you’re trying to achieve. The post-merge hook is designed to run after a successful merge command. A git pull does not necessarily execute a merge, so the post-merge hook is not a reliable way to get something to execute after every git pull.

So maybe if you can describe in more detail exactly what it is you want to happen and why, I can see if I can find you an answer.

Well, I tried and I’m trying new tests with Githook, I can change owner directories and files for apache.

When I customize my hooks working, but the specific script post-merge doesn’t work. I tried create a temporary file on /tmp/ directory and use command chown for change permitions of my Document Root.

I use Git pull to replicate my files of GLPI:

Mini tutorial:

mkdir .git/hooks
mkdir .githooks

git config core.hooksPath .githooks
find .git/hooks -type l -exec rm {} ;
find .githooks -type f -exec ln -sf …/…/{} .git/hooks/ ;

ls
Erros-relatados.md files-upgrade glpi glpi.old README.md

My attempts:

cat .git/hooks/post-merge ( Detail: I use chmod +x on script)

#!/bin/bash

chown apache:apache /var/www/htmlglpi/ -R

touch /tmp/file-test.txt

My config: “git config --list”

user.email=xxx@gmail.com
user.name=root
push.default=simple
pull.ff=no
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
You have new mail in /var/spool/mail/root

Well, I tried and I’m trying use githooks with post-merge for change permitions of directories and files do DocumentRoot of Apache service.

I try with command git pull on DocumentRoot execute this script.

I would like to download files and it uses script post-merge for change permitions of files with githooks.

########################
I customized my githooks

mkdir .git/hooks
mkdir .githooks

git config core.hooksPath .githooks
find .git/hooks -type l -exec rm {} ;
find .githooks -type f -exec ln -sf …/…/{} .git/hooks/ ;

########################

My details:

ls
Erros-relatados.md files-upgrade glpi glpi.old README.md

Example

cat .githooks/post-merge (chmod +x post-merge)

#!/bin/bash

chown apache:apache glpi/ -R
touch /tmp/file.txt

My config git:

git config --list

http.sslverify=false
user.name=Luiz Guilherme
user.email=my-email@com
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.url=http://my-repository/git/root/glpi922-migration.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master

It sounds like you’re trying to prevent permissions problems when performing a git pull command in a web root folder that, presumably, requires a specific permissions structure for the Apache process to be able to serve the files you’re pulling.

Typically, the solution to that has nothing to do with git. If you want to execute a shell as a different user on some form of Unix, you can use either the su or sudo commands. This allows you to switch to the appropriate user context, then you can perform the git pull command, which will update the files as the given user so there are no permission problems. You could even write this process into a script that you could use to do this all in one command.

I hope that helps!

Look doesn’t execute post-emerge

Git server

[root@vm-xxx html]# cat .githooks/post-merge
#!/bin/bash

sudo chown apache:apache /var/www/html/glpi -R
sudo touch /tmp/file.txt

[root@vm-dc-325098-2 html]# ls -la .githooks/post-merge
-rwxr-xr-x. 1 root root 85 Mar 29 15:12 .githooks/post-merge
[root@vm-xxx html]#

###########################

Git Client

[root@vm-dc-xxx2 test]# git init
Initialized empty Git repository in /var/www/html/test/.git/
[root@vm-dc-xxx2 test]# git pull http://127.0.0.1:3000/root/xxxx-glpi.git
remote: Counting objects: 12834, done.
remote: Compressing objects: 100% (5278/5278), done.
remote: Total 12834 (delta 7205), reused 12829 (delta 7204)
Receiving objects: 100% (12834/12834), 587.29 MiB | 14.40 MiB/s, done.
Resolving deltas: 100% (7205/7205), done.

From http://127.0.0.1:3000/root/xxxx-glpi
* branch HEAD -> FETCH_HEAD

[root@vm-dc-xxx2 test] ls -la
total 32
drwxr-xr-x. 7 root root 4096 Mar 29 15:23 .
drwxr-xr-x. 4 root root 33 Mar 13 16:03 …
-rw-r–r--. 1 root root 2201 Mar 29 14:48 Erros-relatados.md
drwxr-xr-x. 4 root root 4096 Mar 29 14:48 files-upgrade
drwxr-xr-x. 8 root root 4096 Mar 29 15:19 .git
drwxr-xr-x. 2 root root 4096 Mar 29 15:12 .githooks
drwxr-xr-x. 18 root root 4096 Mar 29 14:49 glpi
drwxr-xr-x. 16 root root 4096 Mar 29 14:48 glpi.old
-rw-r–r--. 1 root root 1354 Mar 29 14:48 README.md

Looks this links:

https://unix.stackexchange.com/questions/154859/git-pull-in-a-linux-environment-changes-the-owner-of-the-files

https://stackoverflow.com/questions/6298364/fix-permissions-with-git-post-merge

I don’t understand how it’s work.

The solutions there are talking about using a post-update hook, not post-merge.

My solution is to not use a hook at all but to run the commands:

# Logs you in as the apache user
sudo su - apache

# Change directory to the repo you want to pull
cd /var/www/html/glpi

# Perform the pull
git pull

# Exit the apache user session
exit

Then you don’t need to worry about the permissions, because you performed the pull as the apache user.

In any case, I haven’t ever used the post-merge hook, so I’m not sure I can help you achieve what you want using it.

Ahhh, Really with hooks doesn’t update information of permittions, I also create post-update script, but doesn’t run. I’m grateful.