git integration on windows gets stuck
Closed this issue · 21 comments
I've got a developer trying to upload cookbooks from a windows/cygwin environment.
what is working:
knife cookbook upload works as expected - so knife itself is working OK.
a git pull indicates the repo os up to date.
what isn't:
knife spork bump or knife spork upload both get stuck on the git integration.
even with -VV it doesn't tell that much:
It prints: 'Pulling latest changes from git submodules (if any)' and gets no further.
I will ask the developer to to feed back directly on this issue himself.
@atrullmdsol Excellent thanks - if you / the developer could please let me know whether any submodules are present in the repo in question (preferably the output of "git submodule") that would be awesome :)
I've asked him to give this his attention.
I ran the command "git submodule" and it comming up as empty. So the repo does not have any submodules.
@smahmood could I please get you to edit a file under the installed gem?
Edit /wherever-gems-are-installed/knife-spork-1.0.15/lib/knife-spork/plugins/git.rb
and change line 86 from
output = IO.popen("cd #{top_level} && git submodule foreach git pull 2>&1")
to
output = IO.popen("cd #{top_level} && git submodule foreach git pull")
then rerun the failing spork command and paste the full output please?
Here is the output. It is same it was before.
$ knife spork upload zeromq -VV
DEBUG: No chefignore file found at c:/Git/chef-repo/cookbooks/chefignore no files will be ignored
Git: Pulling latest changes from c:/Git/chef-repo/cookbooks/zeromq
Pulling latest changes from git submodules (if any)
But one thing I noticed that I have Gem version knife-spork (1.0.16).
That's OK, version 1.0.16 just involved a change to the foodcritic plugin.
Could you please edit the same file, and insert the following line before line 86:
puts "Before"
and the following line after line 87
puts "Before"
Then paste the output? It'll help me figure out which part of the command is hanging.
Done the changes here is the output. It is same as before.
$ knife spork upload zeromq -VV
DEBUG: No chefignore file found at c:/Git/chef-repo/cookbooks/chefignore no files will be ignored
Git: Pulling latest changes from c:/Git/chef-repo/cookbooks/zeromq
Pulling latest changes from git submodules (if any)
OK, please now try putting the
puts "Before"
before line 82, and
puts "After"
after line 82, then paste the output
I have put Before and After for line 82 and here is the output
$ knife spork upload zeromq -VV
DEBUG: No chefignore file found at c:/Git/chef-repo/cookbooks/chefignore no files will be ignored
Git: Pulling latest changes from c:/Git/chef-repo/cookbooks/zeromq
Pulling latest changes from git submodules (if any)
Before
After
OK, now we're getting somewhere...please remove all debugging lines previously added above, and then add
puts "path: #{path}"
above line 158, and put
puts "toplevel: #{toplevel}"
below line 165. For some reason it looks like the issue is happening during the method which finds the parent directory of the one your cookbook is in - I'm wondering if you're getting stuck in a continual look here. if I'm right, you should see the same toplevel line printed over and over again.
Path for line number 158. Here is the output
$ knife spork upload zeromq -VV
DEBUG: No chefignore file found at c:/Git/chef-repo/cookbooks/chefignore no files will be ignored
Git: Pulling latest changes from c:/Git/chef-repo/cookbooks/zeromq
Pulling latest changes from git submodules (if any)
path: c:/Git/chef-repo
toplevel: c:/Git/chef-repo
Hmm, it's not that then, it's getting stuck somewhere else...OK, please change the lines around 86 and 87 so it ends up as the following:
puts "cd #{top_level} && git submodule foreach git pull 2>&1"
output = IO.popen("cd #{top_level} && git submodule foreach git pull 2>&1")
puts "Ran command"
Process.wait
puts "Command finishes"
I just did the changes and it is comming with the result
$ knife spork upload zeromq -VV
DEBUG: No chefignore file found at c:/Git/chef-repo/cookbooks/chefignore no files will be ignored
Git: Pulling latest changes from c:/Git/chef-repo/cookbooks/zeromq
Pulling latest changes from git submodules (if any)
I put some more debugs in that and it is actually failing at Line number 160. It is not comming out of while loop.
I put some After and Before for the return code of the loop and it is like this.
while return_code == 0
output = IO.popen("cd #{top_level}/.. && git rev-parse --show-toplevel 2>&1")
Process.wait
puts "Before"
puts return_code
return_code = $?
puts "After"
puts return_code
if return_code == 0
top_level = output.read.chomp
end
end
And the output is this and it is just printing the same forever
$ knife spork upload zeromq -VV
DEBUG: No chefignore file found at c:/Git/chef-repo/cookbooks/chefignore no files will be ignored
Git: Pulling latest changes from c:/Git/chef-repo/cookbooks/zeromq
Pulling latest changes from git submodules (if any)
Before
0
After
pid 39564 exit 0
Before
pid 39564 exit 0
After
pid 39564 exit 0
Before
pid 39564 exit 0
After
pid 39564 exit 0
Before
pid 39564 exit 0
After
pid 39564 exit 0
Before
pid 39564 exit 0
After
pid 39564 exit 0
Before
pid 39564 exit 0
After
pid 39564 exit 0
Before
pid 39564 exit 0
After
pid 39564 exit 0
Before
pid 39564 exit 0
After
pid 39564 exit 0
Aha that's interesting, that means Cygwin isn't returning a non-zero exit code when I expected it to...just to double check something, could you please add
puts top_level
after
top_level = output.read.chomp
Cygnus - a world of its own. Thanks for your help so far Jon.
okay I have written the following debug code. For the method def get_parent_dir(path)
top_level = path
puts top_level
return_code = 0
while return_code == 0
output = IO.popen("cd #{top_level}/.. && git rev-parse --show-toplevel 2>&1")
puts "cd #{top_level}/.."
Process.wait
puts "Before"
puts return_code
return_code = $?
puts "After"
puts return_code
if return_code == 0
top_level = output.read.chomp
puts top_level
end
end
top_level
And following is the output
$ knife spork upload zeromq -VV
DEBUG: No chefignore file found at c:/Git/chef-repo/cookbooks/chefignore no files will be ignored
Git: Pulling latest changes from c:/Git/chef-repo/cookbooks/zeromq
Pulling latest changes from git submodules (if any)
c:/Git/chef-repo
cd c:/Git/chef-repo/..
Before
0
After
pid 35968 exit 0
fatal: Not a git repository (or any of the parent directories): .git
cd fatal: Not a git repository (or any of the parent directories): .git/..
Before
pid 35968 exit 0
After
pid 35968 exit 0
c:/Git/chef-repo
cd c:/Git/chef-repo/..
Before
pid 35968 exit 0
After
pid 35968 exit 0
fatal: Not a git repository (or any of the parent directories): .git
cd fatal: Not a git repository (or any of the parent directories): .git/..
Before
pid 35968 exit 0
After
pid 35968 exit 0
c:/Git/chef-repo
cd c:/Git/chef-repo/..
Before
pid 35968 exit 0
After
pid 35968 exit 0
fatal: Not a git repository (or any of the parent directories): .git
cd fatal: Not a git repository (or any of the parent directories): .git/..
Before
pid 35968 exit 0
After
pid 35968 exit 0
c:/Git/chef-repo
cd c:/Git/chef-repo/..
Before
pid 35968 exit 0
After
pid 35968 exit 0
fatal: Not a git repository (or any of the parent directories): .git
cd fatal: Not a git repository (or any of the parent directories): .git/..
Before
pid 35968 exit 0
After
pid 35968 exit 0
c:/Git/chef-repo
cd c:/Git/chef-repo/..
Before
pid 35968 exit 0
After
pid 35968 exit 0
fatal: Not a git repository (or any of the parent directories): .git
cd fatal: Not a git repository (or any of the parent directories): .git/..
Before
pid 35968 exit 0
After
pid 35968 exit 0
It seems like /.. is not required in the line
output = IO.popen("cd #{top_level}/.. && git rev-parse --show-toplevel 2>&1")
Hah! So it's returning a zero exit code when it gets to "fatal: not a git repo"....gimme a few mins and I'll get this fixed and a new version out. The /.. is needed as it's meant to crawl up the dir path until it finds the top level of the git repo. Oh cygwin, how I love you.
OK - before I push a new version, could you please replace the inside of the while loop with this:
output = IO.popen("cd #{top_level}/.. && git rev-parse --show-toplevel 2>&1")
Process.wait
return_code = $?
cmd_output = output.read.chomp
#cygwin, I hate you for making me do this
if cmd_output.include?("fatal: Not a git repository")
return_code = 1
end
if return_code == 0
top_level = cmd_output
end
if it fixes your issue, I'll get a new version pushed to rubygems :)
yes I have replaced the loop code with your one and it has solved the problem. Thanks
Awesome! Just pushed 1.0.17 to rubygems with this fix in it.
Thanks again.