简体   繁体   中英

git clone in .bat script

Is it possible to write a Windows .bat script that executes "git clone" in the middle of the script, so that the script continues? It is always exiting for me.

I am using a 64-bit Git version 2.8.3 from "The Git Development Community" on Windows 7 Enterprise SP1. git.exe is in my path (c:\\program files\\git\\cmd\\git.exe) - it is not indirectly executing via a git.cmd or similar file.

I am able to run a sequence of commands like

git init
git add --all
git commit -m "commit message"

and with these commands, the batch script executes each command continues normally. With

git clone {url}

the script exits immediately, usually with a doubled prompt, suggesting some sort of abnormal exit (even though %ERRORLEVEL% is 0):

git clone {url} new
Cloning into 'new'...
remote: Counting objects: 26, done
remote: Compressing objects: 100% (23/23) done.
remote: Total 26 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (26/26) done.
Checking connectivity... done.
c:\jdev\ppss\finalprep\ant2>c:\jdev\ppss\finalprep>

Common Windows tricks like using "call git clone ..." and "cmd /c git clone ..." do not seem to work. Even "start /wait cmd /c git clone ..." doesn't do it.

Any ideas?

The line following the "git clone" was an IF statement:

git clone {url} subfolder
if "%var%" == "y" (
  @echo some commands went here
) else (
  @echo different commands went here
}

The above IF statement is not a legal DOS if statement (bad ELSE close), but you don't get any error messages from DOS - your script just exits. It looks like the previous command is causing the abort, which in my case happened to be git clone.

This has nothing to do with git whatsoever, strictly cmd.exe nonsense.

In the specific case that was failing, the subdirectory into which "git clone" was writing already existed due to a prior "mkdir". Without the mkdir - without the subdir already existing - the batch script continues after git clone normally, and there was no need for any special tricks like cmd /c

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM