Answers for "powershell script to automate git branches"

0

powershell script to automate git branches

# Local Variables
$base_path = "C:\Temp"
$local_repo_name = "Blitz"
$local_repo_directory = $base_path + "\" + $local_repo_name
 
# Remote Variables
$remote_repo_url = "https://github.com/BrentOzarULTD/SQL-Server-First-Responder-Kit.git"
$branch_name = "master"
 
# Git commands
$clone_cmd = "git clone " + $remote_repo_url + " --branch " + $branch_name + " " + $local_repo_name;
$merge_cmd = "git pull origin"
$branch_check_cmd = "git ls-remote --heads " + $remote_repo_url + " " + $branch_name
 
# Change the working directory
CD $base_path
 
# Check the existence of the remote repo and capture the number of rows that match
# in the result set of the query in $branch_check_cmd.
# Then clone or merge, depending if the local repo exists.
$number_of_matches = Invoke-Expression $branch_check_cmd | Measure-Object
 
IF ( $number_of_matches.Count -eq 1 ) {
 
IF ( -not (Test-Path( $local_repo_name )) ) {
 
# The local repo does not exist, let's grab a copy
Invoke-Expression $clone_cmd
 
} ELSE {
 
# The local repo exists, commence merge to pull in most recent changes
Invoke-Expression $merge_cmd
 
}
 
} ELSE {
 
$wshell = New-Object -ComObject Wscript.Shell
$wshell.Popup("Crap, something went wrong.",0,"Error",0x1)
 
}
Posted by: Guest on June-18-2021

Code answers related to "Shell/Bash"

Browse Popular Code Answers by Language