Want to setup a hook that copies committed files to a particular folder

前端 未结 3 1603
不知归路
不知归路 2021-01-04 09:39

Background: Developing a Facebook app using PHP Laravel framework & MySQL for database.

I have setup Gitlab on our development server and create

相关标签:
3条回答
  • 2021-01-04 10:24

    This post on Seb Duggan blog describe it nicely. You simply create post-receive hook that contain:

    #!/bin/sh
    GIT_WORK_TREE=/path/to/webroot/of/mywebsite git checkout -f
    

    Add it +x flag and it will checkout your repo in given folder.

    0 讨论(0)
  • 2021-01-04 10:25

    Use rsync rather than cp for this operation. It does diff checking automatically. that way your post-commit hook doesn't become needlessly complicated.

    0 讨论(0)
  • 2021-01-04 10:26

    You would need to add to the bare repo (managed by GitLab) a post-receive hook which would:

    • maintain a working tree (git checkout -f master)
    • copy the files you want from that working

    That would be:

    cd ~git/repositories/yourRepo.git/hooks
    touch post-receive
    chmod +x post-receive
    

    You can make sure that hook will only be active if someone pushes on branch master:

    #!/bin/bash
    while read oldrev newrev refname
    do
        branch=$(git rev-parse --symbolic --abbrev-ref $refname)
        if [ "master" == "$branch" ]; then
            # Do something
        fi
    done
    

    For the checkout done by that hook, see "GIT post-receive checkout without root folder", that is:
    make sure you specify --git-dir and --git-work-tree:

    git --git-dir=/path/to/project_root.git --work-tree=/path/to/your/workingtree checkout -f
    

    Again, /path/to/your/workingtree can be:

    • only an intermediate working tree for you to extract from it the relevant files you want to copy.
    • or the path to your app, if you want all the files from master to be updated in the destination directory of your wab app.
    0 讨论(0)
提交回复
热议问题