threads / discuss / 29390

post-update to stash after push to non-bare current branch

Subject: post-update to stash after push to non-bare current branch

## tl;dr

10 messages between Jan 18, 2012 and Jan 21, 2012.

replies: 9people: 3as markdown or json

Neal Kreitzinger· Jan 18, 2012, 17:53 UTC · lore

We use the worktree of git-repos as the webroot for virtual hosts assigned to ports so we can directly test changes to dev and test git-repos. We have some developers who want to develop offline on laptops and push to these non-bare repos so they can test their changes. My plan is to set receive.denyCurrentBranch = warn, and then use the post-update hook on the remote non-bare to do a stash of the worktree and index. My assumption is that post-update hook only executes after a successful push. Correct? I only want to stash the non-bare remote work-tree and index after a successful push to it (effectively doing a git-reset --hard, but also keeping any changes to the worktree/index of the non-bare remote as a safety in case someone does directly make uncommitted changes on the non-bare remote.)

v/r, neal

Neal Kreitzinger· Jan 18, 2012, 18:33 UTC · re: Neal Kreitzinger · lore

Re: post-update to stash after push to non-bare current branch

On 1/18/2012 11:53 AM, Neal Kreitzinger wrote:
Show 13 quoted lines
> We use the worktree of git-repos as the webroot for virtual hosts assigned
> to ports so we can directly test changes to dev and test git-repos.  We have
> some developers who want to develop offline on laptops and push to these
> non-bare repos so they can test their changes.  My plan is to set
> receive.denyCurrentBranch = warn, and then use the post-update hook on the
> remote non-bare to do a stash of the worktree and index.  My assumption is
> that post-update hook only executes after a successful push.  Correct?  I
> only want to stash the non-bare remote work-tree and index after a
> successful push to it (effectively doing a git-reset --hard, but also
> keeping any changes to the worktree/index of the non-bare remote as a safety
> in case someone does directly make uncommitted changes on the non-bare
> remote.)
>

If I manually run git-stash on the non-bare remote after pushing to it from a clone (receive.denyCurrentBranch=warn) it works as expected and leaves the worktree and index matching the new HEAD. However, when post-update runs the git-stash is leaves the worktree dirty. (git 1.7.1)

v/r, neal

Neal Kreitzinger· Jan 18, 2012, 18:51 UTC · re: Neal Kreitzinger · lore

Re: post-update to stash after push to non-bare current branch

On 1/18/2012 12:33 PM, Neal Kreitzinger wrote:
Show 23 quoted lines
> On 1/18/2012 11:53 AM, Neal Kreitzinger wrote:
>> We use the worktree of git-repos as the webroot for virtual hosts
>> assigned
>> to ports so we can directly test changes to dev and test git-repos. We
>> have
>> some developers who want to develop offline on laptops and push to these
>> non-bare repos so they can test their changes. My plan is to set
>> receive.denyCurrentBranch = warn, and then use the post-update hook on
>> the
>> remote non-bare to do a stash of the worktree and index. My assumption is
>> that post-update hook only executes after a successful push. Correct? I
>> only want to stash the non-bare remote work-tree and index after a
>> successful push to it (effectively doing a git-reset --hard, but also
>> keeping any changes to the worktree/index of the non-bare remote as a
>> safety
>> in case someone does directly make uncommitted changes on the non-bare
>> remote.)
>>
> If I manually run git-stash on the non-bare remote after pushing to it
> from a clone (receive.denyCurrentBranch=warn) it works as expected and
> leaves the worktree and index matching the new HEAD. However, when
> post-update runs the git-stash is leaves the worktree dirty. (git 1.7.1)
>
hooks/post-update was:

git stash save echo "worktree+index of non-bare remote current branch stashed for safety"

it created the stash and echoed the message. However, as stated earlier, the worktree is still dirty. I then manually run git-reset --hard and that makes it clean (worktree, index, HEAD match). However, if I add that to the hook it still leaves dirty worktree (index matches HEAD, but worktree doesn't match index)

hooks/post-update is:

git stash save echo "worktree+index of non-bare remote current branch stashed for safety" git reset --hard echo "git-reset --hard on current remote branch to ensure clean state"

message is echoed, but git-reset --hard does not appear to have really worked. (git 1.7.1)

v/r, neal

Junio C Hamano· Jan 18, 2012, 22:38 UTC · re: Neal Kreitzinger · lore

Re: post-update to stash after push to non-bare current branch

Neal Kreitzinger <nkreitzinger@gmail.com> writes:
Show 9 quoted lines
> hooks/post-update is:
>
> git stash save
> echo "worktree+index of non-bare remote current branch stashed for safety"
> git reset --hard
> echo "git-reset --hard on current remote branch to ensure clean state"
>
> message is echoed, but git-reset --hard does not appear to have really
> worked. (git 1.7.1)

Have you checked where in the filesystem hierarchy that script is run (hint: pwd)?

Also it is unclear why you keep saying "stash". What kind of changes are you expecting to be saved to the stash? Will they be changes that are not source controlled that you would rather not to see? In other words, after running "stash" every time somebody pushes and having accumulated many stash entries, when do you plan to pop these stashed changes?

I would have expect that such a repository to reject a push if the working tree is dirty, and run checkout in post-update, though.

Neal Kreitzinger· Jan 19, 2012, 00:32 UTC · re: Junio C Hamano · lore

Re: post-update to stash after push to non-bare current branch

On 1/18/2012 4:38 PM, Junio C Hamano wrote:
Show 15 quoted lines
> Neal Kreitzinger<nkreitzinger@gmail.com>  writes:
>
>> hooks/post-update is:
>>
>> git stash save
>> echo "worktree+index of non-bare remote current branch stashed for safety"
>> git reset --hard
>> echo "git-reset --hard on current remote branch to ensure clean state"
>>
>> message is echoed, but git-reset --hard does not appear to have really
>> worked. (git 1.7.1)
>
> Have you checked where in the filesystem hierarchy that script is run
> (hint: pwd)?
>
echo pwd in post-update echoes /path/WORKTREE/.git in git-push stdout.
Show 6 quoted lines
> Also it is unclear why you keep saying "stash". What kind of changes are
> you expecting to be saved to the stash? Will they be changes that are not
> source controlled that you would rather not to see? In other words, after
> running "stash" every time somebody pushes and having accumulated many
> stash entries, when do you plan to pop these stashed changes?
>
good point. rejection of dirty worktree is a cleaner safety.
> I would have expect that such a repository to reject a push if the working
> tree is dirty, and run checkout in post-update, though.
>

'git-checkout -f' works manually, but in post-update hook it leaves behind dirty worktree, ie. index and HEAD match, but worktree still matches HEAD@{1}. This is the same undesired result git-stash and git-reset --hard leave behind when executed in post-update hook.

v/r, neal

Junio C Hamano· Jan 19, 2012, 01:00 UTC · re: Neal Kreitzinger · lore

Re: post-update to stash after push to non-bare current branch

Neal Kreitzinger <nkreitzinger@gmail.com> writes:
Show 6 quoted lines
>> Have you checked where in the filesystem hierarchy that script is run
>> (hint: pwd)?
>>
> echo pwd in post-update echoes /path/WORKTREE/.git in git-push stdout.
> ...
> 'git-checkout -f' works manually, but in post-update hook...

Stronger hint. Did you run "git checkout -f" in /path/WORKTREE/.git to back that "works manually" claim?

Neal Kreitzinger· Jan 19, 2012, 21:48 UTC · re: Junio C Hamano · lore

Re: post-update to stash after push to non-bare current branch

On 1/18/2012 7:00 PM, Junio C Hamano wrote:
Show 11 quoted lines
> Neal Kreitzinger<nkreitzinger@gmail.com>  writes:
>
>>> Have you checked where in the filesystem hierarchy that script is run
>>> (hint: pwd)?
>>>
>> echo pwd in post-update echoes /path/WORKTREE/.git in git-push stdout.
>> ...
>> 'git-checkout -f' works manually, but in post-update hook...
>
> Stronger hint. Did you run "git checkout -f" in /path/WORKTREE/.git to
> back that "works manually" claim?

(Manual behavior): If pwd is WORKTREE/ then git-checkout has correct effect, ie. worktree, index, and HEAD match. If pwd is WORKTREE/.git/ then git-checkout complains 'must be run in a worktree' and has no effect.

(post-update hook behavior): If pwd is WORKTREE/.git/ then git-push verbage does not complain, and git-checkout exits zero status but has incorrect effect, ie. index and HEAD match, but worktree matches HEAD@{1}. If pwd is WORKTREE/ then git-push complains 'not a git repository', and git-checkout exits non-zero status and has no effect, ie. worktree and index match HEAD@{1}.

Evidence:
(post-update hook script):
MYPWD=`pwd`
echo $MYPWD
pushd /home/neal/FSNMSTHTML
MYPWD=`pwd`
echo $MYPWD
git checkout -f HEAD
if [ $? -ne 0 ]; then
   echo "error on checkout!"
else
   echo "checkout HEAD to non-bare remote current branch after push"
fi
echo $MYPWD
popd
MYPWD=`pwd`
echo $MYPWD
(git-push verbage):
$ git push origin HEAD
Counting objects: 9, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 462 bytes, done.
Total 5 (delta 4), reused 0 (delta 0)
Unpacking objects: 100% (5/5), done.
remote: warning: updating the current branch
remote: /home/neal/FSNMSTHTML/.git
remote: ~/FSNMSTHTML ~/FSNMSTHTML/.git
remote: /home/neal/FSNMSTHTML
remote: fatal: Not a git repository: '.'
remote: error on checkout!
remote: /home/neal/FSNMSTHTML
remote: ~/FSNMSTHTML/.git
remote: /home/neal/FSNMSTHTML/.git
To file:///home/neal/FSNMSTHTML
    cee9269..34dc5a9  HEAD -> master

v/r, neal

Neal Kreitzinger· Jan 21, 2012, 00:13 UTC · re: Neal Kreitzinger · lore

Re: post-update to stash after push to non-bare current branch

On 1/19/2012 3:48 PM, Neal Kreitzinger wrote:
Show 44 quoted lines
> On 1/18/2012 7:00 PM, Junio C Hamano wrote:
>> Neal Kreitzinger<nkreitzinger@gmail.com> writes:
>>
>>>> Have you checked where in the filesystem hierarchy that script
>>>> is run (hint: pwd)?
>>>>
>>> echo pwd in post-update echoes /path/WORKTREE/.git in git-push
>>> stdout. ... 'git-checkout -f' works manually, but in post-update
>>> hook...
>>
>> Stronger hint. Did you run "git checkout -f" in
>> /path/WORKTREE/.git to back that "works manually" claim?
>
> (Manual behavior): If pwd is WORKTREE/ then git-checkout has correct
> effect, ie. worktree, index, and HEAD match. If pwd is
> WORKTREE/.git/ then git-checkout complains 'must be run in a
> worktree' and has no effect.
>
> (post-update hook behavior): If pwd is WORKTREE/.git/ then git-push
> verbage does not complain, and git-checkout exits zero status but
> has incorrect effect, ie. index and HEAD match, but worktree matches
> HEAD@{1}. If pwd is WORKTREE/ then git-push complains 'not a git
> repository', and git-checkout exits non-zero status and has no
> effect, ie. worktree and index match HEAD@{1}.
>
> Evidence:
>
> (post-update hook script): MYPWD=`pwd` echo $MYPWD pushd
> /home/neal/FSNMSTHTML MYPWD=`pwd` echo $MYPWD git checkout -f HEAD
> if [ $? -ne 0 ]; then echo "error on checkout!" else echo "checkout
> HEAD to non-bare remote current branch after push" fi echo $MYPWD
> popd MYPWD=`pwd` echo $MYPWD
>
> (git-push verbage): $ git push origin HEAD Counting objects: 9, done.
> Delta compression using up to 8 threads. Compressing objects: 100%
> (5/5), done. Writing objects: 100% (5/5), 462 bytes, done. Total 5
> (delta 4), reused 0 (delta 0) Unpacking objects: 100% (5/5), done.
> remote: warning: updating the current branch remote:
> /home/neal/FSNMSTHTML/.git remote: ~/FSNMSTHTML ~/FSNMSTHTML/.git
> remote: /home/neal/FSNMSTHTML remote: fatal: Not a git repository:
> '.' remote: error on checkout! remote: /home/neal/FSNMSTHTML remote:
> ~/FSNMSTHTML/.git remote: /home/neal/FSNMSTHTML/.git To
> file:///home/neal/FSNMSTHTML cee9269..34dc5a9 HEAD -> master
>

To get this to work I had to learn more about shell scripting and export the GIT_WORK_TREE git environment variable.

(post-update hook): export GIT_WORK_TREE=/home/neal/FSNMSTHTML git checkout -f HEAD

for more info see this stackoverflow thread http://stackoverflow.com/questions/6635018/reuse-git-work-tree-in-post-receive-hook-to-rm-a-few-files

v/r, neal

Junio C Hamano· Jan 21, 2012, 00:16 UTC · re: Neal Kreitzinger · lore

Re: post-update to stash after push to non-bare current branch

Neal Kreitzinger <nkreitzinger@gmail.com> writes:
Show 6 quoted lines
> To get this to work I had to learn more about shell scripting and export
> the GIT_WORK_TREE git environment variable.
>
> (post-update hook):
> export GIT_WORK_TREE=/home/neal/FSNMSTHTML
> git checkout -f HEAD

Hmm, I thought "cd .. && git checkout -f HEAD" (or "git reset --hard") would have worked.

Neal Kreitzinger· Jan 21, 2012, 00:35 UTC · re: Junio C Hamano · lore

Re: post-update to stash after push to non-bare current branch

On 1/20/2012 6:16 PM, Junio C Hamano wrote:
Show 12 quoted lines
> Neal Kreitzinger<nkreitzinger@gmail.com>  writes:
>
>> To get this to work I had to learn more about shell scripting and export
>> the GIT_WORK_TREE git environment variable.
>>
>> (post-update hook):
>> export GIT_WORK_TREE=/home/neal/FSNMSTHTML
>> git checkout -f HEAD
>
>
> Hmm, I thought "cd ..&&  git checkout -f HEAD" (or "git reset --hard")
> would have worked.

Ok, I just tried that for the first time and it complained "not a git repository: '.'" because it looks like that caused GIT_DIR to no longer point to WORKTREE/.git but instead to WORKTREE/ because GIT_DIR is set to '.' in the post-update script's environment as indicated in this thread: http://stackoverflow.com/questions/6635018/reuse-git-work-tree-in-post-receive-hook-to-rm-a-few-files

v/r, neal

← back to recent threads