Git – List Local Repositories

Background

It is so very easy to share code snippets via git.

And, so I find myself creating little tiny, targeted repositories.

Unfortunately, I have too many of them now.

 

Git Repositories

Local ones

List git repos from targeted folder

listLocalRepository.ps1

Code

param (
		[string] $folder)

		Set-StrictMode -Version 2

# Declare variables
$objListofFiles = $null;
$objListFileContentConfig = $null;

[string] $fileNameSought = $null;
[int]	 $iFileID = 0;
[string] $folderCurrent = $null;

[string] $urlLine = $null;
[string] $stringEmpty = [string]::Empty;

[string]$FORMAT_HEADER_FOLDER_TARGET = "Base Folder :-{0})"
[string]$FORMAT_PROCESSING = "{0}) {1}"
[string]$FORMAT_URL = "`t URL :- {0}"

[string]$FILE_CONFIG = "config";

#Looking for folders named .git
$fileNameSought = ".git"

# In config file look for url tag
$URL_TAG = "url";
$URL_PATTERN = "*" + $URL_TAG + "*";


# If folder not passed in, please use current folder
if ( `
		    ($folder -eq $null) `
		-or ($folder -eq $stringEmpty )`
	)
{

	$folder = (Get-Item -Path ".\" -Verbose ).FullName;

}

$strLog = $FORMAT_HEADER_FOLDER_TARGET -f $folder
Write-Host $strLog

Write-Host $stringEmpty;
Write-Host $stringEmpty;
		
# Where-Object {$_.GetType().Name -eq "FileInfo"} 
# Look for files and folders in path $folder
# Recurse
# Force	
# Show hidden files and folders, as well
# Attributes
#		:- Hidden
$objListofFiles = Get-ChildItem -Path $folder -Recurse -Force  -Attributes Hidden -Include $fileNameSought 

$iFileID = 0;

# enumerate the items array
foreach ($objFile in $objListofFiles) 
{

	#$element
	$iFileID = $iFileID + 1;


	# if the item is a container/directory, then process it.
	if ( $objFile.PSIsContainer)
	{

		# Get Current Folder
		$folderCurrent = $objFile.FullName;

		# display folder name
		$strLog = $FORMAT_PROCESSING -f $iFileID, $folderCurrent;

		Write-Host $strLog
		
		# Get config file in current folder
		$fileConfig = $folderCurrent + "\" + $FILE_CONFIG;
		
		# Read config file
		$objListFileContentConfig = Get-Content -Path $fileConfig
	
		# Look for URL tag	
		$urlLineRaw = $objListFileContentConfig | Where-Object {$_ -like $URL_PATTERN}

		# Strip out undesirables		
		$urlLine = $urlLineRaw;
		
		$urlLine = $urlLine -replace $URL_TAG, $stringEmpty
		$urlLine = $urlLine -replace "=", $stringEmpty
		$urlLine = $urlLine.trim()
		
		# Display URL Tag		
		$strLog = $FORMAT_URL -f $urlLine;

		Write-Host $strLog
		
		Write-Host $stringEmpty;
		Write-Host $stringEmpty;
	
		
	}
	  
}


 

Output

Source Control

Oops, just like Britney, did it again…create a new git repository

Git

GitRepositoryLocalList
Link

 

References

  1. Powershell
    • String
      • Empty String
        • Powershell – Create Empty String with powershell
          Link
      • Replace
        • Use PowerShell to Replace Text in Strings
          Link
    • Get-Content
      • If File or Folder
        • Powershell check if path is folder or file
          Link
        • How do I get only directories using Get-ChildItem?
          Link
    • Character
      • TAB Character
        • How do I type a tab character in Powershell
          Link
    • Array

 

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s