{"thread":{"id":"29205","subject":"Re: post-receive for web deployment","startedAt":"2011-12-19T02:42:56Z","lastAt":"2011-12-19T12:42:37Z","messageCount":4,"participants":["Stephen Major","Johannes Sixt","Sitaram Chamarty"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"181450","messageId":"CALzTOm+sJHF_7WzjD7bCqAiAbQSV0A3hEX1KdWfFzV7-ePzX2w@mail.gmail.com","threadId":"29205","inReplyTo":"CALzTOmJUqzO8H5UxyFaodi98DBJtFvsbQsHsYh1U=Ggq3NRO5A@mail.gmail.com","subject":"Re: post-receive for web deployment","fromName":"Stephen Major","fromEmail":"smajor@gmail.com","sentAt":"2011-12-19T02:42:56Z","receivedAt":"2011-12-19T02:42:56Z","isPatch":false,"sender":{"key":"smajor@gmail.com","avatar":null},"body":"Hello,\n\nI am having some difficulty understanding what I am doing wrong when\nworking with git to deploy a website through the use of a post-receive\nhook on the remote.\n\nHere is the script:\n\n#!/bin/sh\n\nstaging_path=\"/home/user/domains/domain.com/public_html/staging\"\nlive_path=\"/home/user/domains/domain.com/public_html/live\"\n\n\nwhile read oldrev newrev ref\ndo\n\n    branch=$(echo $ref | cut -d/ -f3)\n\n    # ***\n    # update the live site\n    #\n    if [[ \"master\" == \"$branch\" ]]; then\n\n        export GIT_WORK_TREE=$live_path\n        git checkout -f $branch\n\n        echo \"Release has been pushed to production\"\n\n    # ***\n    # we update the staging server with the latest push\n    #\n    elif [[ \"develop\" == \"$branch\" ]]; then\n\n        echo \"Resetting staging tree\"\n        export GIT_WORK_TREE=$staging_path\n\n        git checkout -f $branch\n\n        echo \"Develop has been pushed to staging\"\n\n    fi\n\ndone\n\n\n\nThis is what we have done:\n\ngit checkout develop\ntouch 1 2 3 4 5 6\ngit add .\ngit commit -am \"added some files\"\ngit push origin develop\n\nchecking the remote server now all files are found in:\n/home/user/domains/domain.com/public_html/staging\n\ngit checkout master\ngit merge develop\ngit push origin master\n\nchecking the remote server now all files are found in:\n/home/user/domains/domain.com/public_html/live\n\ngit checkout develop\ngit rm 4 5 6\ngit commit -am \"removed some files\"\ngit push origin develop\n\nchecking the remote server now files 4 5 6 have been removed from:\n/home/user/domains/domain.com/public_html/staging\n\ngit checkout master\ngit merge develop\ngit push origin master\n\nchecking the remote server files 4 5 6 are still found in:\n/home/user/domains/domain.com/public_html/live\n\nWhy is this happening? checking the local repo for master shows the\nfiles are removed there... pulling the latest from origin:master shows\nthe files have been removed... but why were they not removed from the\nworking tree like they were on the staging working tree?\n\n\nwell I think it has something to do with later commits and therefor\nthe working tree of the live server could quickly become out of sync\nwith the development tree\n\na quick test, lets checkout master again and perform the removes\ndirectly on it then push it back:\n\ngit checkout master\ngit rm 1 2 3\ngit commit -am \"removed 1 2 3\"\ngit push origin master\n\nchecking the remote server now files 1 2 3 have been removed from:\n/home/user/domains/domain.com/public_html/live\n\n\nOkay weird so they remove when the commit happens directly on that\nbranch and is pushed to the remote but they dont get removed if the\nremoval happened on a different branch and is merged in then pushed to\nthe remote....\n\nanyone have an explanation or a workaround?\n"},{"id":"181456","messageId":"4EEEDFD8.1050604@viscovery.net","threadId":"29205","inReplyTo":"CALzTOm+sJHF_7WzjD7bCqAiAbQSV0A3hEX1KdWfFzV7-ePzX2w@mail.gmail.com","subject":"Re: post-receive for web deployment","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2011-12-19T06:55:20Z","receivedAt":"2011-12-19T06:55:20Z","isPatch":false,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 12/19/2011 3:42, schrieb Stephen Major:\n> checking the remote server files 4 5 6 are still found in:\n> /home/user/domains/domain.com/public_html/live\n> \n> Why is this happening?\n\nBefore you check out the files, you must ensure that the index matches the\ncontent in the GIT_WORK_TREE that you populate by git checkout.\n\nYou first push a tree that removes 4 5 6 while the index you happen to\nhave still has those files recorded, the files are removed. Your second\npush does not have these files anymore, but the index does not record the\nfiles anymore, either; therefore, git does not act on the files 4 5 6 that\nhappen to live in the other worktree.\n\nPerhaps you should maintain separate index files and set GIT_INDEX_FILE\naccordingly before git checkout.\n\n-- Hannes\n"},{"id":"181462","messageId":"CAMK1S_hjncBxdh4+UXAJbtJnsPWZUpWASyixG8eNcpFLMRpLgw@mail.gmail.com","threadId":"29205","inReplyTo":"CALzTOm+sJHF_7WzjD7bCqAiAbQSV0A3hEX1KdWfFzV7-ePzX2w@mail.gmail.com","subject":"Re: post-receive for web deployment","fromName":"Sitaram Chamarty","fromEmail":"sitaramc@gmail.com","sentAt":"2011-12-19T10:35:03Z","receivedAt":"2011-12-19T10:35:03Z","isPatch":false,"sender":{"key":"sitaramc@gmail.com","avatar":"https://avatars.githubusercontent.com/u/43316?v=4"},"body":"On Mon, Dec 19, 2011 at 8:12 AM, Stephen Major <smajor@gmail.com> wrote:\n> Hello,\n>\n> I am having some difficulty understanding what I am doing wrong when\n> working with git to deploy a website through the use of a post-receive\n> hook on the remote.\n\nThe most common issue I have seen in cases like this is that you need\nto 'unset GIT_DIR'.  In fact, anytime you play around with running\nstuff from *inside* a hook that works fine when you run it from\noutside, you need to check what GIT_ variables are present.\n\nI believe 'unset `git rev-parse --local-env-vars`' is a good idea too;\nprobably much simpler.\n"},{"id":"181465","messageId":"CALzTOmJacwJFNJJo6Y7kjq2pVP8DcgYfWf=bsD0m9oK1XsZ9Yw@mail.gmail.com","threadId":"29205","inReplyTo":"CAMK1S_hjncBxdh4+UXAJbtJnsPWZUpWASyixG8eNcpFLMRpLgw@mail.gmail.com","subject":"Re: post-receive for web deployment","fromName":"Stephen Major","fromEmail":"smajor@gmail.com","sentAt":"2011-12-19T12:42:37Z","receivedAt":"2011-12-19T12:42:37Z","isPatch":false,"sender":{"key":"smajor@gmail.com","avatar":null},"body":"After some playing I found using git clone to export to the staging\npath and then doing git checkout -f master for the production path\nkeeps the files in the production tree clean while leaving any\nun-tracked files in tact, seems what\nJohannes said was true and this seems like a simple workaround... not\nsure about working with indexes like he pointed out.\n\necho \"Resetting staging tree\"\nrm -rf staging.git $staging_path\ngit --work-tree=$staging_path clone ./ staging.git\n\n\necho \"Resetting production tree\"\ngit --work-tree=$live_path checkout -f master\n\n\nOn Mon, Dec 19, 2011 at 2:35 AM, Sitaram Chamarty <sitaramc@gmail.com> wrote:\n> On Mon, Dec 19, 2011 at 8:12 AM, Stephen Major <smajor@gmail.com> wrote:\n>> Hello,\n>>\n>> I am having some difficulty understanding what I am doing wrong when\n>> working with git to deploy a website through the use of a post-receive\n>> hook on the remote.\n>\n> The most common issue I have seen in cases like this is that you need\n> to 'unset GIT_DIR'.  In fact, anytime you play around with running\n> stuff from *inside* a hook that works fine when you run it from\n> outside, you need to check what GIT_ variables are present.\n>\n> I believe 'unset `git rev-parse --local-env-vars`' is a good idea too;\n> probably much simpler.\n"}]}