{"thread":{"id":"1671","subject":"[HOWTO] Using post-update hook","startedAt":"2005-08-27T01:19:10Z","lastAt":"2005-08-27T01:19:10Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"7831","messageId":"7vy86o6usx.fsf@assigned-by-dhcp.cox.net","threadId":"1671","inReplyTo":null,"subject":"[HOWTO] Using post-update hook","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-08-27T01:19:10Z","receivedAt":"2005-08-27T01:19:10Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"The pages under http://www.kernel.org/pub/software/scm/git/docs/\nare built from Documentation/ directory of the git.git project\nand needed to be kept up-to-date.  The www.kernel.org/ servers\nare mirrored and I was told that the origin of the mirror is on\nthe machine master.kernel.org, on which I was given an account\nwhen I took over git maintainership from Linus.\n\nThe directories relevant to this how-to are these two:\n\n    /pub/scm/git/git.git/\tThe public git repository.\n    /pub/software/scm/git/docs/\tThe HTML documentation page.\n\nSo I made a repository to generate the documentation under my\nhome directory over there.\n\n    $ cd\n    $ mkdir doc-git && cd doc-git\n    $ git clone /pub/scm/git/git.git/ docgen\n\nWhat needs to happen is to update the $HOME/doc-git/docgen/\nworking tree, build HTML docs there and install the result in\n/pub/software/scm/git/docs/ directory.  So I wrote a little\nscript:\n\n    $ cat >dododoc.sh <<\\EOF\n    #!/bin/sh\n    cd $HOME/doc-git/docgen || exit\n\n    unset GIT_DIR\n\n    git pull /pub/scm/git/git.git/ master &&\n    cd Documentation &&\n    make install-webdoc\n    EOF\n\nInitially I used to run this by hand whenever I push into the\npublic git repository.  Then I did a cron job that ran twice a\nday.  The current round uses the post-update hook mechanism,\nlike this:\n\n    $ cat >/pub/scm/git/git.git/hooks/post-update <<\\EOF\n    #!/bin/sh\n    #\n    # An example hook script to prepare a packed repository for use over\n    # dumb transports.\n    #\n    # To enable this hook, make this file executable by \"chmod +x post-update\".\n\n    case \" $* \" in\n    *' refs/heads/master '*)\n            echo $HOME/doc-git/dododoc.sh | at now\n            ;;\n    esac\n    exec git-update-server-info\n    EOF\n    $ chmod +x /pub/scm/git/git.git/hooks/post-update\n\nThere are three things worth mentioning:\n\n - The update-hook is run after the repository accepts a \"git\n   push\", under my user privilege.  It is given the full names\n   of refs that have been updated as arguments.  My post-update\n   runs the dododoc.sh script only when the master head is\n   updated.\n\n - When update-hook is run, GIT_DIR is set to '.' by the calling\n   receive-pack.  This is inherited by the dododoc.sh run via\n   the \"at\" command, and needs to be unset; otherwise, \"git\n   pull\" it does into $HOME/doc-git/docgen/ repository would not\n   work correctly.\n\n - This is still crude and does not protect against simultaneous\n   make invocations stomping on each other.  I would need to add\n   some locking mechanism for this.\n"}]}