Archive for February, 2012

The specified baseline is not the latest baseline, so it may not be checked out. Checkout of ‘/svn/yourrepo/!svn/bln/123456′: 409 Conflict (

February 21st, 2012 No comments

Are you getting “The specified baseline is not the latest baseline, so it may not be checked out.  Checkout of ‘/svn/yourrepo/!svn/bln/123456′: 409 Conflict (” when trying to commit to Subversion?  I’ve setup a Subversion write-through proxy to improve multi-site performance.  Unfortunately this seems to be one of the downsides.

The solution to the above is to update and try committing again.  It is possible you may need to wait until your write-through proxy has synced with the master before it will work.

Categories: Uncategorized Tags:

PowerShell Log function with word wrapped output to the screen

February 16th, 2012 No comments

I like to have logging in most scripts I write, and this is the current incarnation of my logging function. It logs to c:\location\of\script.ps1.log (or wherever/whatever your script is named). It uses write-host to output a word wrapped version of the text to the screen. It reads in the window size to determine the best place to cut up the sentence.

# Name of the currently executing script
$ScriptName = $MyInvocation.MyCommand.Path 
# Simple log file name, OurScriptName.ps1.log
$LogFile = $ScriptName + ".log"
# Word wrap function, return word wrapped version of passed string
function WordWrapStr($str)
	# Holds the final version of $str with newlines
	$strWithNewLines = ""
	# current line, never contains more than screen width
	$curLine = ""
	# Loop over the words and write a line out just short of window size
	foreach ($word in $str.Split(" "))
		# Lets see if adding a word makes our string longer then window width
		$checkLinePlusWord = $curLine + " " + $word
		if ($checkLinePlusWord.length -gt (get-host).ui.rawui.windowsize.width)
			# With the new word we've gone over width
			# append newline before we append new word
			$strWithNewLines += [Environment]::Newline
			# Reset current line
			$curLine = ""
		# Append word to current line and final str
		$curLine += $word + " "
		$strWithNewLines += $word + " "
	# return our word wrapped string
	return $strWithNewLines
# Log function, append passed string to log file
function Log([string]$logline)
    $timestamp = Get-Date -f "yyyy-MM-dd HH:mm:ss"
    $StdLogLine = "$timestamp> $logline"
	# Add the log line to our log file in ascii with timestamp
    Add-Content $LogFile $StdLogLine -encoding ascii
    # Print to the screen the word wrapped version (no timestamp)
	write-host (WordWrapStr $logline)
Log "This text will first be appended to $LogFile, ascii encoded.  Also cut up the text and print it out word wrapped to the screen.  It works even with really long lines."

Example with and without word wrapped write-host:

Categories: Uncategorized Tags:

Batch file bootstrap PowerShell script for easy double click running

February 16th, 2012 No comments

The scenario is you have a PowerShell script that takes no paramaters and prompts the user for all the information it needs. How do you make it extra simple for people to check it out of source control and run it?

You have 1 .bat or .cmd file in the root of the folder. Create a subfolder like internal and put all your ps1 files in there. Here is what I put together so you could just double click the .bat/.cmd file and have your PowerShell script execute without worry.

@echo off
REM Check to see if Powershell is in path
for %%X in (powershell.exe) do (set FOUND=%%~$PATH:X)
if not defined FOUND (
	echo Please install PowerShell v2 or newer.
	exit /b 1

REM Check to see if we have powershell v2 or later
PowerShell.exe -command "& { if ($host.Version.Major -lt 2) { exit 1 } }"
	echo Please upgrade to PowerShell v2 or later.
	exit /b 1

REM Set scriptDir to directory the batch file is located
set scriptDir=%~dp0
echo Running powershell.exe %scriptDir%internal\MyScript.ps1
REM Note the RemoteSigned in case the system is defaulted to restricted
powershell.exe -ExecutionPolicy RemoteSigned -command "& { "%scriptDir%internal\MyScript.ps1"; exit $LastExitCode }"
if "%ERRORLEVEL%" NEQ "0" (
	echo There may have been a problem with MyScript.  Please read the above text carefully before exiting.

After replacing MyScript with the name of your script, stick the contents in MyScript.cmd in your main directory. Make sure you have your powershell script in a subdirectory called internal. When the user double clicks on the file we check if PowerShell is in the path and that it is v2 or greater. We abort if either of those conditions are false. Finally we execute the PowerShell script with paramaters to ensure it runs on a new system without having the execution policy set yet. If you exit your powershell script with a non-zero the batch file will remind the user to read carefully before the window closes.

Categories: Uncategorized Tags: ,

[SOLVED] svn user commits _svn folder !?!?!?

February 8th, 2012 No comments

Names and paths changed to protect the innocent :)

Here’s a quick one that wreaked a moment of havoc. A user had comitted _svn folders to the repository. The build server uses _svn instead of .svn by way of an environment variable SVN_ASP_DOT_NET_HACK. This caused the continuous integration server to stop updating since it freaked out trying to pull down a _svn folder over a _svn folder.

This is what it looked like in the log:

PS J:\> svn log --verbose -r 1234 https://svnserver/svn/WidgetX/trunk
r1234 | johnsmith | 2012-02-08 11:14:09 -0800 (Wed, 08 Feb 2012) | 1 line
Changed paths:
   A /trunk/src/newthing
   A /trunk/src/newthing/0.jpg
   A /trunk/src/newthing/1.jpg
   A /trunk/src/newthing/2.jpg
   A /trunk/src/newthing/9.jpg
   A /trunk/src/newthing/_svn
   A /trunk/src/newthing/_svn/prop-base
   A /trunk/src/newthing/_svn/props
   A /trunk/src/newthing/_svn/text-base
   A /trunk/src/newthing/_svn/tmp
   A /trunk/src/newthing/_svn/tmp/prop-base
   A /trunk/src/newthing/_svn/tmp/props
   A /trunk/src/newthing/_svn/tmp/text-base
Just another commit

To fix a user comitting _svn folders:

# My environment variable was set so checkouts use _svn instead of .svn (legacy reasons)
# Unset it so we get .svn folders as normal
# Checkout the branch so we get a working copy with .svn instead of _svn as usual
svn co https://svnserver/svn/WidgetX/trunk
# Round up the offending _svn folders and delete them!
get-childitem -recurse -force | where { $ -eq "_svn" } | foreach {  svn delete ""$_.fullname"" }
svn commit -m "Cleaning up _svn folders" trunk

I tried to reproduce this scenario using .svn folders, but svn smartly told me it was a reserved name. Adding _svn it didn’t complain at all (see bug). There might be some way to force a .svn folder in, in which case you can use this procedure except set the SVN_ASP_DOT_NET_HACK variable to any value instead of unsetting it. Also change $ -eq “_svn” to $ -eq “.svn”.

Categories: Uncategorized Tags: ,