gitpowershellcommand-lineautomationsourcetree

Add SourceTree Remotes Programmatically


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.


Solution

  • 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.