{"thread":{"id":"7828","subject":"Pushing to a non-bare repository, round 2","startedAt":"2007-04-25T08:04:15Z","lastAt":"2007-04-25T08:04:15Z","messageCount":1,"participants":["Matthieu Moy"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"40384","messageId":"vpqps5subgg.fsf@bauges.imag.fr","threadId":"7828","inReplyTo":null,"subject":"Pushing to a non-bare repository, round 2","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@imag.fr","sentAt":"2007-04-25T08:04:15Z","receivedAt":"2007-04-25T08:04:15Z","isPatch":false,"sender":{"key":"git@matthieu-moy.fr","avatar":"https://avatars.githubusercontent.com/u/14709?v=4"},"body":"Hi,\n\nFollowing up to a recent thread:\n\nhttp://lists.zerezo.com/git/msg419909.html\n\nI wrote a (very primitive) update hook that updates the working tree\non the remote side when pushing to its current branch.\n\n==== cut here : .git/hooks/update ====\n\n#!/bin/bash\n\nif [[ \"$1\" = $(git symbolic-ref HEAD) ]]; then\n    GIT_DIR=$(pwd)\n    cd ..\n    git reset --soft $2\n    git merge $3\n    git reset --soft $2\nfi\n\n==== end ====\n\nIt has several problems. First, the\n\nGIT_DIR=$(pwd)\ncd ..\n\nis ugly. Indeed, since I push to the URL of the tree of the remote\nrepository, git knows about the location of this tree, but it doesn't\nseem to tell it to the update hook. So, I hardcoded \"..\" here. And the\nGIT_DIR the hook receives isn't terribly informative, it's just \".\",\nand having a relative path here means I have to do this\nGIT_DIR=$(pwd) before doing any \"cd\".\n\nThen, \n\n    git reset --soft $2\n    git merge $3\n\ndoes the update (there should also be something to complain loudly if\nthere is a risk of conflict here, but let's say it's on the\ntodo-list).\n\nBut then, the refs/heads/<branch> does not point anymore to the point\nwhere git expects it. So, I need another\n\n    git reset --soft $2\n\nto get back to the point it used to be. I find that pretty ugly\ntoo :-(.\n\nI really think there should be something about this in git itself. Not\nnecessarily something to actually update the tree, but at least, make\nit easy to actually \"update\" the tree after a push.\n\nIn mercurial, for example, the above hook is just:\n\n[hooks]\nchangegroup = hg update \n\nin .hg/hgrc. It tells hg to run \"update\" each time a group of changes\nis pushed into the repository. And update _knows_ which revision the\ntree used to point to, and which revision is the head of the branch.\n\nAny opinion?\n\nThanks,\n\n\n(at the moment, I need this to easily push changes to a machine to\nmake them available to users, letting them the choice between git and\nrsync to get a fresh tree. Most of the users won't have git and won't\nwant to learn it)\n\n-- \nMatthieu\n"}]}