git - Having issue while implementing custom gitlab hook -


i implementing custom gitlab hook. while 1 pushes in master, want update specific file. commit change , push remote origin. hook looks below:

clone_repo(){      //cloning specifc branch on my_app dir        export git_work_tree="path/my_app"     } cd_app(){     cd my_app } update_file(){   // updating random.java } commit_file(){     git commit -m "commit hook" random.java }   while read oldrev newrev refname  if [ ${refname} = "refs/heads/master" ]       clone_repo      cd_app && update_file      commit_file && push_it      exit 0  fi done 

the hook running cd_app && update_file not doing suppose (not updating update_file). assuming cd_app not changing dir (via shell print).

but testing when set refname="refs/heads/master" before if checking, works fine!

could not find gitlab logs custom_hooks. , seems missing something. can guys give me further reference or identify doing wrong?

here's how did system.

first, git_work_tree this:

$ # git_work_tree  $ pwd /home/git/loging_at_post_receive $  $ git remote -v origin  /home/git/repositories/gitlab-user/loging_at_post_receive.git/ (fetch) origin  /home/git/repositories/gitlab-user/loging_at_post_receive.git/ (push) $  $ ls log.txt $  $ git log --oneline 5aecefe first commit 

next, hook script follows:

$ # bare repository $ pwd /home/git/repositories/gitlab-user/test_hook.git $  $ cat hooks/post-receive #!/bin/bash clone_repo(){     #cloning specifc branch on my_app dir      export git_work_tree="/home/git/loging_at_post_receive" } cd_app(){     cd /home/git/loging_at_post_receive } update_file(){     date >> log.txt     echo "update_file" } commit_file(){     git --git-dir=.git add log.txt     git --git-dir=.git commit -m "commit hook"     echo "commit_file" } push_it(){     git --git-dir=.git push origin master     echo "push_it" } while read oldrev newrev refname  if [ ${refname} = "refs/heads/master" ]       clone_repo      cd_app && update_file      commit_file && push_it      exit 0  fi done 

then, git push pc gitlab. (please pay attention "remote:" area)

$ # on pc $ echo 1 >> readme $ git commit -am 'test' $ git push origin master [master 9aed67e] test  1 files changed, 1 insertions(+), 0 deletions(-) counting objects: 5, done. writing objects: 100% (3/3), 239 bytes, done. total 3 (delta 0), reused 0 (delta 0) remote: update_file remote: [master 0ce599e] commit hook remote:  1 file changed, 1 insertion(+) remote: commit_file remote: /home/git/repositories/gitlab-user/loging_at_post_receive.git/ remote:    5aecefe..0ce599e  master -> master remote: push_it https://gitlab-server/gitlab-user/test_hook.git    712a3d1..9aed67e  master -> master 

as result

$ # git_work_tree  $ pwd /home/git/loging_at_post_receive $  $ git log --oneline 0ce599e commit hook 5aecefe first commit $  $ git log origin/master --oneline 0ce599e commit hook 5aecefe first commit 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -