@echo on
rem %1 is the git repo
rem %2 is the reponame
rem %3 is the name of the file you want to get
rem %4 is the target test location folder that is rootpath /testpath


rem if the target location does not exist thenn create it
if NOT exist %4 (mkdir %4) 1>nul
if not exist %4 (goto Error0)
cd %4

echo "Creating log file VCSlog" >VCSLog.txt
echo %* >>VCSLog.txt

rem then clone the remote repo
set repoPath=%1^/%2

Rem clone the remote rep but only last version of each file - this dosnt' work on local repo 

if not exist .^\%2 (git clone -n %repoPath% --depth 1) 2>>VCSLog.txt
if exist  .^\%2 (cd .^\%2) else (goto Error1)
echo. >>..\VCSLog.txt
git pull origin master >>..\VCSLog.txt
echo repo %repoPath% was cloned or updated >>..\VCSLog.txt

rem checkout the file you need	
git checkout HEAD %~3 1>>..\VCSLog.txt

rem succeeded then get the file into the testpath else you didn't get the file you wanted
if exist %~3 (xcopy %~3  .. /s/e/q/y) >>..\VCSLog.txt
echo files %~3  were checked out >>..\VCSLog.txt

rem get back to the test path 
cd ..
if not exist %~3 goto Error2

rem  success
del VCSLog.txt
exit 0

rem Can't access the target location for the test
:Error0
echo Can't access the target location for the test >>VCSLog.txt
echo exit 10

rem remote repo coulduld not be cloned
:Error1
echo remote repo could not be cloned >>VCSLog.txt
echo exit 11


:Error2
echo file could not be checked out >>VCSLog.txt
echo exit 21