agiannis
8/11/2015 - 3:11 PM

Upload git changes to ftp with the help of WinSCP

label: git

@echo off
REM Upload git changes to ftp with the help of WinSCP
REM USAGE: go to the project root directory and just hit upload_changes. 
REM The root directory must have a upload.conf file with winscp_host,remote_path data. 
REM "winscp_host" is the name of WinSCP host name. 
REM Check WinSCP directory is set correctly

REM Get changes from n latest commits
set latest=%1
REM set winscp_host="testsite.com"
REM set remote_path="/public_html"
set local_path="%cd%\git_changed_files\"

REM Set path data (eg winscp_host=_2015/demolab)
for /f "delims== tokens=1,2" %%G in (upload.conf) do set %%G=%%H

REM create a local directory git_changed_files and put inside all git changes
for /f "usebackq tokens=*" %%A in (`git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT HEAD~%latest% HEAD`) do IF "%%A" NEQ "update.sql" (echo f | xcopy /f /y  "%%A"  "%local_path%\%%A") > nul

REM upload local folder to remote
"C:\My Programs\WinSCP\WinSCP.com" %winscp% %winscp_host%  /command "option confirm off" "put "%local_path%"  "%remote_path%"" "bye"

REM Removing local directory
RD /s /q %local_path%
echo.
%extra_comand%