Browsing"Test Lab"

PowerShell Prompt with Mercurial Status

Dec 24, 2009 by     1 Comment     Posted under: Test Lab

I like Linux shell a lot, and like Rails commands, and I like PowerShell. It is about time that someone from Microsoft wakes up from GUI dream and give power to the command prompt.

I wanted to play a little with PowerShell and read one interesting blog from Mark Embling and his blog post named My Ideal Powershell Prompt with Git Integration.

My last blog post was about transition from Subversion to Git, but the day after I give chance to Mercurial and stay with it. It’s totally nonsensical to speak which is better, because they both are great. I think this is same like question about Rails vs. Django, Github vs. BitBucket.

I found myself in Mercurial, and it is (for me) easier to use in Windows environment. So in spirit of Mark Embling post, I’ll write my Ideal PowerShell Prompt for Mercurial or hg if you want.

I haven’t use PowerShell a lot, I like it because I can use Linux Shell commands ls, cp, … And never used/write PowerShell scripting. But I think I can read code and I can quick adapt in new code/language and find way to accomplish tasks but as many with a little help from Google :)

There are two scripts, one is PowerShell Profile script and another with functions to get mosto of hg status/branch, named:

  • Microsoft.PowerShell_profile.ps1 (inside it calls the second one)
  • hgutils.ps1 (functions for hg)

Because I have no time right now to explain all code, I urge you to read Mark Embling great blog post for more information.

Here is the code for Microsoft.PowerShell_profile.ps1:

# My preferred prompt for Powershell.
# Displays mercurial branch and stats when inside a mercurial repository.

# You can clone it by
# hg clone https://xajler@bitbucket.org/xajler/powershell-prompt-for-mercurial/
# And find source here:
# http://bitbucket.org/xajler/powershell-prompt-for-mercurial/src/

# including mercurial functions to use it for prompt
. (Resolve-Path D:/Documents/WindowsPowershell/hgutils.ps1)

function prompt {
	$path = ""
	$pathbits = ([string]$pwd).split("\", [System.StringSplitOptions]::RemoveEmptyEntries)
	if($pathbits.length -eq 1) {
		$path = $pathbits[0] + "\"
	} else {
		$path = $pathbits[$pathbits.length - 1]
	}
	$userLocation = '@ ' + $path
	$Host.UI.RawUi.WindowTitle = $userLocation
    Write-Host($userLocation) -nonewline -foregroundcolor Green       

   if (isCurrentDirectoryMercurialRepository) {
        $status = mercurialStatus
        $currentBranch = mercurialBranchName

        Write-Host(' [') -nonewline -foregroundcolor Yellow
        Write-Host($currentBranch) -nonewline -foregroundcolor Magenta
        Write-Host(' A' + $status["added"]) -nonewline -foregroundcolor Green
        Write-Host(' M' + $status["modified"]) -nonewline -foregroundcolor Yellow
        Write-Host(' D' + $status["deleted"]) -nonewline -foregroundcolor Cyan
        Write-Host(' !' + $status["missing"]) -nonewline -foregroundcolor Magenta
        Write-Host(' ?' + $status["untracked"]) -nonewline -foregroundcolor Red        

        Write-Host(']') -nonewline -foregroundcolor Yellow
    }    

	Write-Host('>') -nonewline -foregroundcolor Green
	return " "
}


And here is the code for hgutils.ps1:

# Mercurial (hg) functions
# Kornelije Sajler (http://learnaholic.me)
# Adopted from Git version of:
# Mark Embling (http://www.markembling.info/)

# You can clone it by
# hg clone https://xajler@bitbucket.org/xajler/powershell-prompt-for-mercurial/
# And find source here:
# http://bitbucket.org/xajler/powershell-prompt-for-mercurial/src/

# Is the current directory a Mercurial repository/working copy?
function isCurrentDirectoryMercurialRepository {
    if ((Test-Path ".hg") -eq $TRUE) {
        return $TRUE
    }

    # Test within parent dirs
    $checkIn = (Get-Item .).parent
    while ($checkIn -ne $NULL) {
        $pathToTest = $checkIn.fullname + '/.hg'
        if ((Test-Path $pathToTest) -eq $TRUE) {
            return $TRUE
        } else {
            $checkIn = $checkIn.parent
        }
    }

    return $FALSE
}

# Get the current branch
function mercurialBranchName {
    $currentBranch = ''
    hg branch | foreach {
        $currentBranch += $_
    }
   # Write-Host($currentBranch)
    return $currentBranch
}

# Extracts status details about the repo
function mercurialStatus {
    $untracked = 0
    $added = 0
    $modified = 0
    $deleted = 0
    $missing = 0

    $output = hg status

    #$branchbits = $output[0].Split(' ')
    #$branch = $branchbits[$branchbits.length - 1]

   # Write-Host($output)
    $output | foreach {
        if ($_ -match "^R") {
            $deleted += 1
        }
        elseif ($_ -match "^M") {
            $modified += 1
        }
        elseif ($_ -match "^A") {
            $added += 1
        }
        elseif ($_ -match "^\!") {
            $missing += 1
        }
        elseif ($_ -match "^\?") {
            $untracked += 1
        }
    }

    return @{"untracked" = $untracked;
             "added" = $added;
             "modified" = $modified;
             "deleted" = $deleted;
             "missing" = $missing}
}


I put scripts on great Mrecurail repository hosting BitBucket so you can clone it by command

hg clone https://xajler@bitbucket.org/xajler/powershell-prompt-for-mercurial/

And find it on this BitBucket page. Also have README if you don’t know how to use it.

I also use great Console2 to host my PowerShell, if you like my below screenshot in BitBucket repository you can also find Console settings xml (console.xml).

console-powershell-mercurial

Sorry for any mistakes that made in this blog post, because I’m in hurry!!!

Hope you’ll find it useful and ask questions if you have it.

Moving from Subversion to Git

Dec 20, 2009 by     No Comments    Posted under: Test Lab

Yep, that day have come. I’m really sick of all Centralized Source Control (or Code) Managements (SCM). I have troubles earlier with Subversion (SVN) but I also have high tolerance and even in the beginning of my recent project have been dropping revisions to recreate the repository from confusing errors.

But few days ago I just got no new added files, after Commit in VisualSVN Server! Modified and deleted were good and committed properly. It was “sort of” my mistake but somehow TortoiseSVN started to mark added files as non-versioned, but why? I haven’t got this issue before, and now when I browse at VisualSVN Server trunk of my project through Web, there were no newly added and now modified files from my latest commits?!!

But this is not what awake my anger and despair, and make me to loose faith in SVN and go to look for Git. Today, when I was trying to commit a Revision, in first try it complained about some newly added directory, but then on new commit, I got error “No such revision 188”, WTF?

last_svn_prompt

OK, I went to browse (like most would do on Google) to find solution. First one, was something like export your repository to new one, then, blah, blah.. No way!

Second one was, go to its Repository and find current file, found it, but it was 187 revision. I start digging and found 188 files somewhere along the files in Repository. Delete it, no help, “No such revision 188”!. And I’m pissed.

I’m going for Git, final, no excuses (maybe one day I’ll try Mercurial), but first, give it a chance to Git. After all it is Source Version by Linus Torvalds, and I even watched on YouTube his talk in Google about Git, it was interesting, many would be offended, but this is his way, and I like the guy!

But get on the dirty job. I would really, really like to migrate all revisions and importe them to Git. After all I commented them well, and TortoiseSVN “Show Log” is one great application for searching past revisions.

So there is a git-svn which confused me a lot because once (I think) it was used as git-svn, but now git svn. But I was impressed by it. It really take all my revisions from SVN to Git, and it so easy!!!

First you have to create a file users.txt. In it write all users that have committed to a project in format:

xajler = Kornelije Sajler <xajler@gmail.com>
VisualSVN Server = VisualSVN Server  <visual@visualsvn.com>

Note: I was using VisualSVN Server, and its default user is “VisualSVN Server”. This user made initial (or first) commit. BTW, this is a imaginary email for VisualSVN user!

mkdir project_tmp
cd project_tmp
git svn init http://code.yoursite.net/svn/project/trunk/ --no-metadata
git config svn.authorsfile ../users.txt
git svn fetch

That’s it, three Git commands. And after a couple of minutes all 187 revisions have been migrated, but not last one, 188 which was giving me error. First, I want only these files (not-able-to-commit ones) to overwrite the existing in Git repository, but then I saw that SVN failed to do last two commits.

So, I just copy all the files to new location remove all .svn folders and just replaced migrated files in Git Repository. I was at start of these project also using Git and SVN, so I copied from past .gitignore file. It purpose is to discard all files, directories, extensions, that are written in it.

At my job we use Visual SourceSafe 2005 and it is a painful to work with, SVN was a little relief but after 187 revisions, I gave up. Hope that Git would be better, and I’ll have no more idiotic problems like I was having with both SVN and SourceSafe.

If you have more insights about this error, and have you (and better why you) cope with Centralized SCMs, please do, write a comment!

Installing Mono, Gtk# and MonoDevelop Preview on Windows 7

Sep 7, 2009 by     1 Comment     Posted under: Test Lab

These days while playing with CakePHP and internationalization in it provided by good old gettext (also used by WordPress, Drupal,…). I start to wonder does this i18n is also for Winidows or only for *nix operating system. While deep diving across and beyond Google I found a gettext installation for Windows, install binaries, but I wanted more!

I want to use gettext with C# and found a internationalization for gettext in Mono.Posix assembly with simple example. Nice, I rushed at once to download the latest Mono 2.4.2.3 and install it. So, I really don’t know how Mono runs on Visual Studio or SharpDevlop, but I remembered of MonoDevelop (was once a fork of SharpDevelop to Linux, but to day this projects are quite different from each other), a nice development application for Mono on Linux and it has preview release for Windows.

monodevelop

The Problem and Solution

The problem is when I installed a MonoDevelop, it just crash over and over. In comments on download page, some folks also have same problem, MonoDevelop just crashes. It is clearly written on download page that MonoDevelop requires Gtk# for .NET 2.12.9-2. But the same Gtk# is available, and downloaded, and installed with Mono.

The solution for me is plain and simple. Even though Gtk# came with Mono, I downloaded Gtk# provided as link on MonoDevelop and installed it, and as you can guess MonoDevelop runs, works, builds, compiles and even debugs like charm. A nice piece of software and it had a quite nice logo. Happy coding with MonoDevelop!

Target Process 2.16 Installation on Windows 7 and SQL Server 2005 Express

Aug 23, 2009 by     2 Comments    Posted under: Test Lab

Target Process logoTargetProcess is a proprietary agile project management tool supports Scrum, Extreme Programming (XP). From the start of August, and with version 2.15 TargetProcess have support for Kanban. A Kanaban is new switch in Software Development from Agile to Lean – also known as JIT (Just-In-Time). For more about Kanban read writings of Michael Dubakov CEO of TargetProcess and Derick Bailey on Los Techies.

The notion of existence for TargetProcess (TP) I’ve had from Steve Bohlen excellent screencast series Autumn Of Agile (never finished, though). TP is just plain simple, user-friendly, fun to work with, and TP have Community Edition for 5 users pack for free. Community Edition version is more than enough for me and for many others.

The installation of TP is quite trivial even though I have had problems with IIS 7 Application Pool user on Windows 7 RC release, but with this final version, no problem, quick and smooth, of course only if prerequisites are satisfied.

I think TP is made with Spring.NET, uses NHibernate for ORM, I think NVelocity is templeate engine, and its user friendliness entirely comes from ExtJS.

Gathering Reuquirements

First we have to download TargetProcess Community Edition. It can only be through signup, and as I remember, you have to wait for TP reply mail one or more days. In mail is a link to download TP and also licence and good thing is, once signup, you’ll get all TP updates, revisiting this mailed link.

TP requirement is a SQL Server database either 2005 or 2008 and what is good Express version are supported but for Windows 7 we have to install SQL Server 2005 SP3, older, I think are not compatibile with Windows 7.

SQL Server 2005

TP have requirement for SQL Server to use SQL Server Authentication. It is no problem if you haven’t install SQL Server, you can use Mixed mode during installation and apply password for sa user, but if you have SQL Server installed, you have to do two things, easily done with SSMS Express (and use SP3 version for Windows 7) :

  1. Log on to your SQL Server SSMS Express then right-click on your server (SQLEXPRESS), choose Properties. It popup the window where you have to choose Security and on Server Authetication click radio button SQL Server and Windows Authentication, save it, and it requires to restart the server – easily done through SQL Server Configuration Manager or Administrative Tools – Services
  2. Enable sa user and give him a password – In your SSMS SQLEXPRESS instance click on Security node in tree view to expand, then expand Logins. Here is the sa user, right-click on him Properties in popup window first choose Status. sa user is disabled by default so in status there is Login and we have to click radio button Enabled, and when is sa user is enabled on General in popup window you have to set password for our sa user.

Note: It is not wise to use sa user in production or over Internet, this is only for testing and local purpose. For production you could create new user and give ownership on database created for TP and used through installation.

TP have a also requirement for .NET 3.5 SP1 to be installed and IIS 7 which is not installed by default in Windows 7 but can be easily done with Turn Windows features on or of (inside Programs in Control Panel). Where you have to choose (check) Internet Information Services. It is clever to check every feature inside except FTP Server (of course you can check it if you need it). It can all be done through Web Platform Installer, but for me it is better to do it manually!

Smooth installation

Now the installation of TP should be quick and smooth, and only thing you have to enter is Database server (.\SQLEXPRESS), and password entered during installation of SQL Server or added through Security/Logins. After install, you can run TP from your local Web Server with username admin and password admin.

First thing when you’re logged inside TP is to apply your given licence, choosing Admin -> Licence. If you have serial number you will choose Automatically or Manually if you have .lic file on your disk, and in People link in upper menu change the admin account password to whatever you want. Nice thing is, at your home page is a link to generate the sample project from which you can learn a lot.

Enjoy in TargetProcess because, it is a wonderful product. If you have some questions please ask and stay Lean and Agile!