Reputation: 715
I'm writing a suite of PowerShell scripts to automate setting up new developer workstations on Windows 7.
I am at the step where I'd like all of our repositories to automatically clone the develop/ branch and map to a file structure that is our team standard.
The way we structure our checkouts is C:/Projects/{ProjectName}/{RepositoryName} which map to our Project / Repository heirarchy in BitBucket Server. Checking the projects out with git automatically will be trivial from a powershell script.
The issue I'm trying to resolve is how to automatically add the repository to SourceTree's list of local repositories on the system, and mirror the folder structure within SourceTree (so there would be a tree called {ProjectName} and it would have several repositories beneath it.)
I would be fine with a one-step "import all remotes" action but that doesn't seem to be available. I don't want to require the user to manually add each project in SourceTree which could be error-prone and tedious.
Is there a way to edit the list of repositories that SourceTree keeps? I would be fine with a solution that depended on an internal implementation (editing a config file that might change between versions, for example). It's not a problem for us to maintain this.
Upvotes: 1
Views: 258
Reputation: 303
I wanted to do something similar so I created a batch script for it.
@echo off
rem Setup variables and create labview folder if it does not exist
set "stfolder=%USERPROFILE%\AppData\Local\Atlassian\SourceTree"
set "folder=pathToWhereYouWantTheRemoteRepositoriesClonedTo"
if not exist %folder% (
mkdir %folder%
)
rem set username and pw
git config --global credential.helper manager
rem create builds and modify sourcetree files
set rep="HTTPSLinktoRemoteRepository"
call :CloneRep "nameOfRepositoryLocally"
exit /b %errorlevel%
:CloneRep
setlocal
rem clones the repository into a new folder
set "curDir=%folder%\%~1"
if not exist "%curDir%\.git" (
git clone %rep% "%curDir%"
) else (
echo %curDir% repository already exists
)
set "replace=</ArrayOfTreeViewNode>"
set "replaced=%~1"
set "replacedX=<TreeViewNode xsi:type="BookmarkNode"><Level>0</Level><IsExpanded>false</IsExpanded><IsLeaf>true</IsLeaf><Name>%replaced%</Name><Children /><CanSelect>true</CanSelect><HasError>false</HasError><Path>%folder%\%replaced%</Path><RepoType>Git</RepoType></TreeViewNode>"
call :replaceinfile bookmarks "ArrayOfTreeViewNode>"
set "replace=</ArrayOfString>"
set "replaced=%~1"
set "replacedX= <string>%folder%\%replaced%</string>"
call :replaceinfile opentabs "ArrayOfString>"
endlocal
EXIT /B 0
:replaceinfile
setlocal EnableDelayedExpansion
rem modifies the file to include references to the new local repository
(for /F "delims=" %%a in (%stfolder%\%~1.xml) do (
set "line=%%a"
set "newLine=!line:%~2=!"
if "!newLine!" neq "!line!" (
set "newLine=%replacedX%"
)
echo !newLine!
if "!newLine!" neq "!line!" (
echo !replace!
)
)) > %stfolder%\%~1new.xml
move /y %stfolder%\%~1new.xml %stfolder%\%~1.xml
exit /b 0
The script should clone the remote repository and modify the sourcetree bookmarks.xml and opentabs.xml to include references to the new repository.
by repeating the set rep="HTTPSLinktoRemoteRepository
and call :CloneRep "nameOfRepositoryLocally"
lines the script can add multiple repositories.
Upvotes: 0
Reputation: 715
With some additional sleuthing, I was able to determine that the %appdata%/Local/Atlassian/SourceTree folder was the location for storing configurations. In that folder is a bookmarks.xml. It's simple to reproduce this structure to automatically create bookmarks, and when starting SourceTree afterward, it picks up any changes that have been made.
Upvotes: 2