Posts Under Tag: Source Control

Using PowerShell to Automate TortoiseSVN Updates

If you find yourself working with a code base using SVN for source control (bla..), then you may as well spend a few minutes automating the periodic updates you’ll need to get from trunk.

Let’s do this with TortoiseSVN and PowerShell.  If you haven’t set up a PowerShell profile, that’s will be the first step.  Details on how to do that can be found on this TechNet article, or follow these steps:

Open a Windows Powershell prompt by pressing the Windows key, type Powershell in the search box, then right-click the Windows Powershell icon and choose ‘Run as administrator’.  At the Windows PowerShell prompt, check if your PowerShell profile exists:

Test-path $profile

If it doesn’t exist, the result from the above command will be False.  To create a profile, execute this command:

New-item –type file –force $profile

Now that the PowerShell profile is created, you’ll see the following directory was created: C:\Users\{your user name}\Documents\WindowsPowerShell.  To edit the profile, you can either open it up in your text editor of choice or have PowerShell do that for you:

Notepad $profile

Next is to create a function in the PowerShell profile that will be used to update the your SVN repo from trunk:

function fn_update_trunk {tortoiseproc /command:update /path:"C:\Work\ProjectX\trunk"}

What the above line is doing is creating a function that uses the TortiseSVN Automation Commands to update your local repository.  In this example, the SVN update command is being performed on the pre-existing repository I have at C:\Work\ProjectX\trunk.

Save the PowerShell profile file and you’re almost ready.  The next step is to create an shortcut that can be clicked to run the automated process.  I have this shortcut on my desktop.  In order to create that, from the Windows desktop right-click and choose New -> Shortcut.  A window will appear prompting you for the location of the shortcut.  Place the following text in the location box:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -command fn_update_trunk

This needs to be the location of the PowerShell executable on your computer.  For ease of use, this is adding a parameter to bypass the PowerShell execution policy.  Finally, a command is added to run the function that was created in the profile to update the SVN repository.

Click the Next button and you’ll be prompted to name the shortcut.  Once the shortcut is created, click on it and it’ll open a PowerShell prompt which will then open TortiseSVN and automatically update your SVN trunk.

Tags: , Filled Under: Programming Posted on: June 18, 2015

Updating a Forked GitHub Repository

If you’re going to contribute to an existing project on GitHub, your first step is to fork the repository.  The easiest way to do that is to look in the upper-right of the repo’s GitHub page and press the Fork button.  Doing this will fork, or create a copy of the repository under your GitHub account.

Fork a repo from GitHub via the browser

Fork a repo from GitHub via the browser

So you now own a copy of that repository.  What happens if the Master branch of the parent repository you forked from gets updated and your fork is now out of date?  Well, you may first start by reading the GitHub documentation on Syncing a Fork.  The instructions start by setting a remote upstream location.

$git remote add upstream

You can think if this as instructing your fork as to where it came from and where it should update from.  Now that your fork knows where it needs to update from, you have to actually fetch that code.

$git fetch upstream

At this point you have your local fork and the upstream repository.  The GitHub documentation states you should then merge with the upstream/master.  However, if you do that and make a change, commit it, and then submit a pull request, what your pull request would look like would be your changes plus all the commits merged in from the origin.  Luckily this Stackoverflow answer provides an alternative, continuing with a rebase.

git rebase upstream/master

The rebase rewrites your master branch so that any of your commits that aren’t in the upstream/master are put on top of that branch.  This eliminates the problem where your merge with the origin would include all of your merging activity.  Finally, after the rebase on to the upstream you’ll need to force push this all to your fork on GitHub.

git push -f origin master

As noted on the Stackoverflow answer, the -f is only needed the first time after you’ve rebased.  At this point your own fork of the repository on GitHub should now be up to date with the repository you forked it from.

Tags: , Filled Under: Programming Posted on: September 20, 2013

Changing the Local Path of a Repo in GitHub for Windows

GitHub for Windows has changed the way I’ve thought about Git.  As a Windows user, the console commands native to Git always seemed a bit foreign. Before GitHub for Windows, I used Git Extensions in Visual Studio 2010.  It was somewhat familiar, but still not as ‘obvious’ to use as the eventual GitHub for Windows client.

GitHub for Windows has a lot going on UI-wise.  It’s WPF based with a very modern look that sometimes hides its functionality in obscure context menus that you find by right-clicking.  That’s why I expected to find a menu option to change the local storage directory of a GitHub repo I was working with.

By default, GitHub for Windows does in fact have a configurable default storage directory.

GitHub Options

In the Tools -> Options area, the default storage directory can be set. The key word here is Default, meaning that it’s not per repo, it’s for everything.

So if I have a setting for a default storage directory, I must get a setting for each repository to change its actual storage directory if I wanted to, right?  No, you don’t.  After pondering this, and eventually figuring out the solution to this problem, I don’t really think this is a design flaw.  I think it could somehow be on purpose.  Either way, it took me quite a while to figure out how to change the local storage directory for a repo I cloned from GitHub.

Here’s how you do it.  From GitHub for Windows right-click on the name of the repository you need to move.  This will open a context menu where you need to choose ‘stop tracking this repo’.

Stop Tracking menu option

Once your local clone of the repo isn’t tracked, switch down to the github area and click on the github id of the owner of the repo you need.  In my case, it’s ‘justinsaraceno’.  Doing this will display the available repos for cloning locally.  Instead of pressing the clone icon/link on the repo, right-click on the repo name.  This will bring up a context menu where you need to choose ‘clone to…’.  Doing this will prompt you for the local file path you’d like to use.

Clone To location option

Of course this could have all been avoided if you chose the ‘clone to…’ menu option when you first cloned the repo.

Tags: Filled Under: Programming Posted on: September 29, 2012

VisualSVN Has Stepped It Up With Version 3.0

VisualSVN has improved Visual Studio integration, works great with VS2012, has new features, and personal licenses are now FREE!

It versions, it merges, it branches, it switches, it diffs, it patches, it integrates with VS2012! Don’t know Git? ForGit about it! VisualSVN 3.0 can be yours for absolutely nothing!

Several years ago, I bought a license of VisualSVN for personal use.  I remember researching source control solutions and my criteria was:

  • Integrate with Visual Studio’s Solution Explorer
  • Be light-weight
  • Easy to use
  • No source hosting fees

VisualSVN, a Subversion plugin for Visual Studio, was the clear winner.  Team Foundation Server (TFS) is too bloated for personal use in my opinion, and distributed version control systems were just coming on the scene.

I use TFS at work, Git and GitHub for open source software projects, and I’ve stuck with Subversion and VisualSVN for maintaining source control of my personal closed-source projects.  Why?  Because it’s still so easy to use, totally controlled by me, and it’s now free.

Free Personal License

When Visual Studio 2012 was officially released recently, I installed it and then went to the VisualSVN download page for their Visual Studio plugin.  Not only was I amazed that they now officially supported VS2012, I saw they were on a new major version (3.0), and it was free!  Yay, no upgrade cost!  So how exactly do you qualify for a free personal (now called Community) license?  Well, if you install it on a computer that’s not a member of an Active Directory domain, the Community License, which is free, can be used.  They also have a free license for open source developers.  Licensing details can be found here.

Favorite New Features

Compatible with Visual Studio 2012

VisualSVN 3.0 integrates nicely with VS2012.  Just like in previous versions,  a VisualSVN menu item is installed in to the IDE.  It also provides the familiar visual indicator in the Solution Explorer if a file has been modified locally.

The familiar VisualSVN solution explorer integration show what files are under source control and their state.

New Pending Changes Window

There is now a Pending Changes window, very much like the one TFS uses.  From this window you can commit, un-commit, diff, and open any changed file in the solution.

VisualSVN now allows you to see pending file changes; something familiar to those who have used TFS.

Now Uses Visual Studio’s Built-in Diff Window

Besides now being free, this is my favorite new feature of version 3.0.  Previously, the diff window was external to Visual Studio and looked very old-school.  VisualSVN now diff’s directly in Visual Studio!  Not only that, it looks great and makes it plainly obvious what has changed.  You even get a a visual indicator bar to the right of the screen to indicate the location of all changes file-wide.

VisualSVN 3.0 now shows file diffs directly in Visual Studio by default instead of an external tool.

Subversion as a whole may not have the hype distributed source control gets lately.  It still has its place and is being used by many developers.  I’m glad to see VisualSVN decided to modernize their product and make it free.

Tags: Filled Under: Programming Posted on: August 24, 2012