I wanted to share some scripts I whipped up to make traversing my fossil
checkouts easier in Windows. If Richard et al., want to add these kinds of
commands to the fossil.exe directly, i'm all for it... I just wanted to
share what's making my fossil use easier until then. =)

*root.cmd*
This walks up the path until it finds _FOSSIL_ (aka, the "root" folder of
your current checkout) and leaves you there. If it can't find _FOSSIL_, it
will let you know that you're not within an active checkout and leave you in
the directory you started in.

@echo off
SET _startingLocation=%CD%
SET _=

:check
IF [%_%]==[%CD%] (
   echo You are not within an open checkout.
   cd %_startingLocation%
   GOTO :EOF
)

SET _=%CD%
IF NOT EXIST _FOSSIL_ (
   CALL :goUp
) ELSE (
   GOTO :end
)
goto :eof

:goUp
CD ..
CALL :check

:end
SET _=
SET _startingLocation=


*root.ps1*
This script is a powershell version of root.cmd. I would usually make
root.cmd just an alias for root.ps1, but sometimes I find myself in a cmd
prompt and transferring state (such as your current directory) to a parent
shell is messy. Easier in this case to maintain two different scripts for
two different shells.

try {
    $root = Get-CheckoutRootPath
    pushd $root
} catch {
    write-host "You are not within an open checkout."
    write-host
}


*addextra.ps1*
My team and I develop in C#. As such, we most often only need to add *.cs
and *.csproj files to our enlistment. Visual Studio likes to create tons of
extra files when you build (objs and dlls and exes and cache files and
such), making the 'fossil extras' and 'fossil addremove' commands not quite
so useful. This script takes the output of 'fossil extras'* *and filters it
to select our desired files, and then changes to the root of the checkout
and adds each file (since fossil add doesn't seem to support the paths that
fossil extras emits unless you're in the root of the checkout... even if you
prepend a "/" it just gets confused).

[CmdletBinding(SupportsShouldProcess=$true)]
param()

try {
    $root = Get-CheckoutRootPath
    pushd $root
    $extras = fossil extras
    $foundFiles = $false
    foreach($file in $extras) {
        if ($file.EndsWith(".cs") -or $file.EndsWith(".csproj")) {
            if ($pscmdlet.ShouldProcess($file, "fossil add")) {
                fossil add $file
            }
            $foundFiles = $true
        }
    }

    if(-not $foundFiles) {
        write-host "No matching files to add."
    }
    popd
} catch {
    write-host "$error"
}


*addextra.cmd*
This is a simple call-through batch file that lets me use addextra.ps1 (a
powershell script) from a regular command prompt. It must live in the same
folder as addextra.ps1. (Note, this pattern is not specific to addextra.cmd
- you can copy and rename this .cmd file to match the name of any other .ps1
file and it will automatically enable that powershell script for cmd prompt
execution. =)

@powershell -File %~dpn0.ps1 %*


*Get-CheckoutRootPath.ps1*
This is the powershell function that enables the scripts 'root.ps1' and
'addextra.ps1' as listed above.

param([string]$dir = $($(Get-Location).Path))

function GetRootPath($dir) {
    $found = Test-Path $($dir + "\_FOSSIL_")
    if(-not $found) {
        $parent = Split-Path $dir -Parent
        if($parent -ne "") {
            GetRootPath $parent
        } else {
            throw "You are not within an open checkout."
        }
    } else {
    $dir
    }
}

GetRootPath $dir


Happy fossiling,

-jer
_______________________________________________
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users

Reply via email to