Re: [git-users] git push does not update remote workdir

2015-05-01 Thread Thomas Ferris Nicolaisen
On Friday, May 1, 2015 at 11:08:43 PM UTC+2, Thomas Ferris Nicolaisen wrote:

 On Wednesday, April 29, 2015 at 1:53:42 PM UTC+2, Konrád Lőrinczi wrote:

 Unfortunately push-to-checkout did not result files in workdir after 
 pushing to server, so it was not usable for me.


 https://github.com/git/git/commit/0855331941b723b227e93b33955bbe0b45025659


 Not sure if I'm missing out on something obvious here, but 
 push-to-checkout works as expected when trying it out:


Correction: the push-to-checkout hook only works since Git 2.4.

Git 2.3 introduced this updateInstead configuration, which is what I showed 
off in my example. The push-to-checkout hook is more a fix for those cases 
where the target repository gets manipulated between pushes or something 
like that. Depending on your use-case you may not need that.

-- 
You received this message because you are subscribed to the Google Groups Git 
for human beings group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to git-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [git-users] git push does not update remote workdir

2015-05-01 Thread Thomas Ferris Nicolaisen
On Wednesday, April 29, 2015 at 1:53:42 PM UTC+2, Konrád Lőrinczi wrote:

 Unfortunately push-to-checkout did not result files in workdir after 
 pushing to server, so it was not usable for me.


 https://github.com/git/git/commit/0855331941b723b227e93b33955bbe0b45025659


Not sure if I'm missing out on something obvious here, but push-to-checkout 
works as expected when trying it out:

# Note that Git version must be = 2.3
[master][~/temp/foo-web]$ git --version
git version 2.3.6 

# Take some random repo and clone it to a remote location:
[~/temp]$ git clone foo foo-web
Cloning into 'foo-web'...
done.


# So, let's pretend that this non-bare repository is on our web-host:
[~/temp]$ cd foo-web

# Configure allowing incoming pushes
[master][~/temp/foo-web]$ git config receive.denyCurrentBranch updateInstead

# Create the basic hook, as examplified in the test in 
 https://github.com/git/git/commit/0855331941b723b227e93b33955bbe0b45025659
[master][~/temp/foo-web]$ vim .git/hooks/push-to-checkout

### contents of the push-to-checkout hook:

/bin/sh
echo 2 updating from $(git rev-parse HEAD)
echo 2 updating to $1

git update-index -q --refresh  git read-tree -u -m HEAD $1 || {
status=$?
echo 2 read-tree failed
exit $status
}

## EOF


# Make the hook executable
[master][~/temp/foo-web]$ chmod +x .git/hooks/push-to-checkout

#Now let's take it for a spin. Go back to the original repo:
[master][~/temp/foo-web]$ cd ..
[~/temp]$ cd foo
[master][~/temp/foo]$ git remote add web ../foo-web
[master][~/temp/foo]$ git push web master
Everything up-to-date

# OK, that wasn't very impressive. Make some changes first, a new file for 
example:
[master][~/temp/foo]$ echo `random_word`  heya.txt; git add .;git commit 
-m `random_word`
[master b6765e2] overpaint
 1 file changed, 1 insertion(+)
 create mode 100644 heya.txt

# Away we go:
[master][~/temp/foo]$ git push web master
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 322 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To ../foo-web
   eb2711a..b6765e2  master - master
[master][~/temp/foo]$ cd ..
[~/temp]$ cd foo-web

# TADA:
[master][~/temp/foo-web]$ ls
README   foo  heya.txt

Does that work for you?

-- 
You received this message because you are subscribed to the Google Groups Git 
for human beings group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to git-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [git-users] git push does not update remote workdir

2015-04-28 Thread Thomas Ferris Nicolaisen
I didn't get into the details of this discussion, but I just wanted to 
shoot in that there is a new hook since Git 2.3 called push-to-checkout. 
Perhaps that would be the right thing here. Nice to know about anyhow:

https://github.com/git/git/commit/0855331941b723b227e93b33955bbe0b45025659

-- 
You received this message because you are subscribed to the Google Groups Git 
for human beings group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to git-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [git-users] git push does not update remote workdir

2015-04-27 Thread Konstantin Khomoutov
On Fri, 24 Apr 2015 12:54:57 -0700 (PDT)
Konrád Lőrinczi klorin...@gmail.com wrote:

 Well, I noticed, that I had a bug in  post-receive hook, so here is
 the fixed one:
 
 #!/bin/sh
 export GIT_WORK_TREE=/domains/site/test-workdir/
 export GIT_DIR=/domains/git/site-bare.git/
 cd $GIT_DIR
 git checkout -f
 
 However, the problem still remains.
 
 Also GIT_TRACE=1 did not help, there was no any useful info.

GIT_TRACE only traces your local Git instance, and has nothing to do
with the Git process working on the server side.

On the other hand, exporting GIT_TRACE=1 will be an interesting thing
to do before running `git checkout -f` if you're debugging your hook
script like I have outlined in my first response.

P.S.
I would restate that you supposedly has to start using `set -e` or,
better, `set -e -u` in your hook script.  Start with [1] and the
pointers it gives.  Otherwise your hook script, as a program, is almost
as broken with regard to error handling as a typical PHP program: when
an error happens, it gets logged somewhere and the execution continues.
This is a broken logic: if you *know* you should ignore an error
running a particular command, you specifically arrange for ignoring its
error return, like with

  a_command_which_is_ok_to_fail || true

to make the script not exit when that command fails.
Otherwise anything which gone wrong will terminate the scipt.

1. http://serverfault.com/q/143445/118848

-- 
You received this message because you are subscribed to the Google Groups Git 
for human beings group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to git-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [git-users] git push does not update remote workdir

2015-04-27 Thread Konrád Lőrinczi
I learned a lot about git usage from you, so thanks for your suggestions  
help!

I tried your suggestions, and found no additional error message, which can 
explain why the working dir is not updated. 

BUT: you wrote, that the working dir is updated only, when there was at 
least one change in local repo, it was committed, then I push to the git 
bare repo on the server.
Yeah, it seems, this was the cause why the working dir was not updated.

I tried the post-update hook, too, but no difference.

My problems:
1) Basically I would like to update the working dir, when I do a git push 
to the server.
Is it possible?


2) My second problem, what happens, when I delete a file from the local 
repo?
Is it also deleted from the working dir?
So 
git checkout -f
does a copy (which leaves deleted files in target dir)?
or
does a mirror (which deletes the deleted files from target dir, so will 
always have exactly the same content )?

Basically I would need mirroring.


Any ideas for these 2 problems?


Thanks is advance,
Konrad Lorinczi





2015. április 24., péntek 21:42:47 UTC+2 időpontban Konstantin Khomoutov a 
következőt írta:

 On Fri, 24 Apr 2015 11:59:33 -0700 (PDT) 
 Konrád Lőrinczi klor...@gmail.com javascript: wrote: 

 [...] 
  mkdir /domains/git/site-bare.git 
  cd /domains/git/site-bare.git 
  git --git-dir=. --work-tree=/domains/site/test-workdir/. init 
  git config receive.denycurrentbranch ignore 
  cd /domains/git/site-bare.git/hooks 
  nano post-receive 
  # add the following content until # end 
  #!/bin/sh 
  export GIT_WORK_TREE=/domains/site/test-workdir/. 
  export GIT_DIR=/domains/git/site-bare.git/.git 

 ^^^ This. 

 The GIT_DIR environment variable tells Git where the Git database 
 directory is located. 
 But a bare Git repo *is* the Git database directory in itself. 
 That makes it different from a normal Git repository, in which the 
 root directory is the so-called work tree, and the Git database 
 directory is typically located beneath and called .git. 

 Obviously, in a bare repo, there's no .git subdirectory. 
 Bare repos even typically have the .git suffix appended to their names 
 precisely to signify they already are .git directories. 

 [...] 

  git push web-remote master 
  
  
  Once I also got the 
 [...] 
  remote: fatal: Not a git repository: 
  '/domains/git/site-bare.git/.git' 

 That most probably was the message a Git program run from your hook 
 script yelled at you.  Since you did not enable/provide proper error 
 reporting in your hook script, even though `git checkout` failed with 
 that error message, the script continued to chug along and hence the 
 receive operation succeeded. 

 [...] 
  Later I did not get such Not a git repository error. 

 Did the hook run? 
 If you had no new commits to push, the hook was not run. 

  But anyway, the workdir is not filled with content, this is my 
  problem. 
  
  UPDATE: If I do git checkout -f of the server, then the workdir is 
  updated. So this means that the post-receive hook is not executed. 
  
  Any idea why the remote workdir is not updated? 

 There are many issues with your approach. 

 The first one is that your GIT_DIR setting is incorrect (and outright 
 nonsensical) as I expained above.  But I'd say it is not needed at all: 
 when the hook runs, it already has all the Git-related settings in its 
 environment.  So you only has to provide it with the location of your 
 work tree. 

 The second problem is that the hook is supposed to fail (that is, to 
 exit with a non-zero exit code; supposedly having printed out an error 
 message to the standard error stream before doing that) as soon as it 
 encounters an error.  In your case I'd start with placing the line 

   set -e -u 

 somewhere right after the shebang line (that #!/bin/sh thing).  This 
 would ask the shell to crash and burn as soon as any command it 
 executed failed (and that was not properly handled by the script) or 
 the script attempts to dereference a variable which was not assigned a 
 value. 

 I would also say that the correct event for the hook like yours is 
 post-update, not post-receive.  Receiving deals with, well, receiving, 
 while post-update means the heads (branches) were already updated with 
 their new commits. 

 And another pro-tip.  If you need to debug a script, running 
 non-interactively, a useful trick is to wrap it in another script, 
 something like this: 

   #!/bin/sh 
   set -e -u 
   orig=`dirname '$0'`/post-update.orig 
   exec /bin/sh -x $orig $@ /var/tmp/my-hook-trace.log 21 

 Where your post-update.orig is the original script to debug, and the 
 script I showed is temporarily made the post-update hook. 
 The -x command-line option instructs the shell to trace the execution 
 of the script it's told to run, and that trace ends up in the log file 
 -- with all the diagnostic and error messages. 


-- 
You received this message because you are subscribed to the