Skip to content

Instantly share code, notes, and snippets.

@nokotan
Created May 13, 2021 12:24
Show Gist options
  • Save nokotan/77e17be91207bb68ca31c0d701c4c702 to your computer and use it in GitHub Desktop.
Save nokotan/77e17be91207bb68ca31c0d701c4c702 to your computer and use it in GitHub Desktop.
@echo off
setlocal
chcp 65001 > nul
set GitLog=%USERPROFILE%\git.log
set GitTmp=%USERPROFILE%\git.tmp
:: echo ^> git %* >> %GitLog%
if "%1" equ "rev-parse" goto rev_parse
if "%1" equ "ls-tree" goto ls_tree
if "%1" equ "log" goto log
if "%1" equ "update-index" goto update_index
git %*
:: git %* >> %GitLog% 2>&1
goto :eof
:rev_parse
:: git.exe %* | cygpath -w -f -
:: git.exe %* | cygpath -w -f - >> %GitLog%
for /f "delims=" %%1 in ('git %*') do (
if "%%1" neq ".git" (
cygpath -w "%%1"
:: echo %%1 >> %GitLog%
:: cygpath -w "%%1" >> %GitLog%
)
)
goto :eof
:ls_tree
git %*
:: git %* >> %GitLog% 2>&1
echo %5 > %GitTmp%
goto :eof
:update_index
set /p TargetFile=< %GitTmp%
git %* %TargetFile%
:: git %* %TargetFile% >> %GitLog% 2>&1
goto :eof
:log
:: Very very nasty hacks...
:: When passed commit hash reference (ex. 46ac3776ccd3844^1),
:: CMD drops carret(^) and causes invalid commit reference
set Arg4=%4
set Args=%1 %2^=%3 %Arg4:~,-1%^^^^%Arg4:~-1% %5 %6 %7 %8 %9
:: echo ^> git %Args% >> %GitLog%
git %Args%
:: git %Args% >> %GitLog% 2>&1
goto :eof
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment