Can't using pipe within “git.exe fetch origin” under Windows batch
I wrote a batch to check and deploy the rails app from github, the batch file see below. The problem is
git.exe fetch origin | find "remote: Counting Objects" always returns
errorlevel 1, even when we have new commits. I must terminate the Rails App first, because some files are locked (
*.jars) and cause the
git pull command to fail.
I search and found below topic, but even using
git.exe instead of the
git.cmd, the problem still exists.
- Check if pull needed in Git
- git bash : how to check if there's a new commit available
I try to using a temp file to store
git.exe fetch origin result, but if seems this command always print the result to the console.
git pull | find "Already up-to-date." if %errorlevel% == 1 (
REM @echo off set path=%path%;C:\Program Files\Git\bin;D:\jruby-1.6.7\bin set JRUBY_OPTS=--1.9 git.exe fetch origin | find "remote: Counting objects" if %errorlevel% == 0 taskkill /f /im:jruby.exe git pull | find "Already up-to-date." if %errorlevel% == 1 ( REM start cucumber.bat REM do something else when update ) REM RAILS tasklist | find "jruby.exe" if %errorlevel%==1 ( echo @rails s > rail.bat echo @exit >> rail.bat start cmd /c rail.bat ) exit
One Solution collect form web for “Can't using pipe within “git.exe fetch origin” under Windows batch”
At a guess I’d say it’s breaking because the ‘Counting objects’ line shows a dynamic progress indicator, but don’t quote me on that.
... git fetch origin git branch -a --no-merged |find "remotes/origin" if %errorlevel% == 0 taskkill /f /im:jruby.exe ...
You might also want to limit it to just the current branch:
git branch -a --no-merged |find "remotes/origin/mybranch"