git clone in .bat script

14,341

Solution 1

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.

Solution 2

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

Share:
14,341
John Elion
Author by

John Elion

Updated on June 22, 2022

Comments

  • John Elion
    John Elion almost 2 years

    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?