Adam's "Blog"

That's all, really.

TortoiseGit Shortcuts for Visual Studio

In my last post I went over the External Tools setup I use to launch TortoiseSVN from Visual Studio. Nearly all of those commands (all except Update) can be reused for TortoiseGit with a minor tweak. And better still, they can be launched from the same menu item. All we need is a little script to detect whether we are working in a git repository or an SVN working copy and launch TortoiseProc.exe or TortoiseGitProc.exe as appropriate.

(TortoiseWhicheverProc.cmd) download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
@ECHO OFF
SET FOUND=
SET SEARCHPATH=%CD%
SET LASTSEARCHPATH=

ECHO %~nx0: finding source control dir for %SEARCHPATH%

:loop
CALL :checkdir "%SEARCHPATH%"
IF NOT "%FOUND%"=="" GOTO %FOUND%
SET LASTSEARCHPATH=%SEARCHPATH%
FOR %%i IN ("%SEARCHPATH%\..") DO SET SEARCHPATH=%%~fi
IF "%SEARCHPATH%"=="%LASTSEARCHPATH%" goto notfound
GOTO loop

:checkdir
ECHO Checking %~f1
IF EXIST "%~f1\.git\." SET FOUND=git
IF EXIST "%~f1\.svn\." SET FOUND=svn
GOTO :EOF

:svn
echo It's svn!
echo Running: tortoiseproc.exe %*
start tortoiseproc.exe %*
goto :EOF

:git
echo It's git!
echo Running: tortoisegitproc.exe %*
start tortoisegitproc.exe %*
goto :EOF

:notfound
echo Not found!
exit /b 1
goto :EOF

Just save that batch file somewhere in your search path, replace TortoiseProc.exe with TortoiseWhicheverProc.cmd in each of those commands (except the Update), and it will magically work for SVN and git. Check the “Use Output window” box to see the batch file’s output.