Skip to content

Instantly share code, notes, and snippets.

@patrickmmartin
Created November 29, 2011 23:59
Show Gist options
  • Save patrickmmartin/1407251 to your computer and use it in GitHub Desktop.
Save patrickmmartin/1407251 to your computer and use it in GitHub Desktop.
a little script I wrote to demo who simple branching in SVN can be, and how scriptable it is
@echo off
:: some macros to improve legibility
set CHECK_DELETE= || ( echo deletion failed - exiting & exit /b )
set CHECK_CREATE= || ( echo creation failed - exiting & exit /b )
set CHECK_COMMIT= || ( echo commit failed - exiting & exit /b )
set CHECK_READ= || ( echo read failed - exiting & exit /b )
set CHECK_RENAME= || ( echo rename failed - exiting & exit /b )
:: clean up
if exist ScratchRepo ( ( echo prior repo - deleting & rmdir /s /q ScratchRepo)
%CHECK_DELETE% )
if exist trunk ( echo prior checkout exists - deleting & rmdir /s /q trunk)
%CHECK_DELETE% )
if exist testbranch ( echo prior checkout exists - deleting & rmdir /s /q testbranch)
%CHECK_DELETE% )
:: init from scratch
( echo creating scratch repo & svnadmin create ScratchRepo
%CHECK_CREATE% )
:: generate the URL style REPO url
set REPO_URL=file:///%CD:\=/%/ScratchRepo
echo setting up example project in repository
echo this is the very first commit to this location > scratch.txt
( svn mkdir %REPO_URL%/trunk -m"creating trunk" --username Admin 1>nul
%CHECK_COMMIT% )
( svn mkdir %REPO_URL%/branches -m"creating branches" --username Admin 1>nul
%CHECK_COMMIT% )
( svn import scratch.txt %REPO_URL%/trunk/scratch.txt -m"initial revision" --username Admin 1>nul
%CHECK_COMMIT% )
echo checking out trunk
( svn co %REPO_URL%/trunk trunk 1> nul
%CHECK_READ% )
echo modifying trunk
echo some changes to this file > trunk\scratch.txt
echo copying trunk to branches/testbranch
( svn copy %REPO_URL%/trunk %REPO_URL%/branches/testbranch -m"copying trunk" --username Admin 1>nul
%CHECK_COMMIT% )
echo switching WC to branches/testbranch
( svn switch %REPO_URL%/branches/testbranch trunk 1>nul
%CHECK_COMMIT% )
ren trunk testbranch %CHECK_RENAME%
echo committing change to branches/testbranch
( svn commit testbranch -m"committing modifications" --username Admin 1>nul
%CHECK_COMMIT% )
echo checking out a clean trunk
( svn co %REPO_URL%/trunk trunk 1> nul
%CHECK_READ% )
echo merging testbranch back into clean trunk
svn merge %REPO_URL%/branches/testbranch trunk > nul
@patrickmmartin
Copy link
Author

The how

Run it on Windows in a command shell

the output on the first run will be

creating scratch repo
setting up example project in repository
checking out trunk
modifying trunk
copying trunk to branches/testbranch
switching WC to branches/testbranch
committing change to branches/testbranch
checking out a clean trunk
merging testbranch back into clean trunk

The result

this script creates a scratch and some branches and demonstrated a merge
the end result is a modified checkout, ready for review and commit to trunk

The point

Demonstrate branching and scripting some techniques that are useful with SVN

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment