Skip to content

Commit

Permalink
add extension repo verification
Browse files Browse the repository at this point in the history
  • Loading branch information
kairu-ms committed Nov 12, 2024
1 parent 621caf5 commit 246dfdc
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
21 changes: 18 additions & 3 deletions .githooks/pre-push.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,26 @@ if ($editableLocation) {
$AZURE_CLI_FOLDER = Split-Path -Parent (Split-Path -Parent $editableLocation)
}

# Get extension repo paths and join them with spaces
$ExtensionRepo = Split-Path -Parent $PSScriptRoot

# verify if the $ExtensionRepo is in the output of azdev extension repo list
$Extensions = (azdev extension repo list -o tsv) -join ' '
if ($Extensions -notlike "*$ExtensionRepo*") {
Write-Host "The current repo is not added as an extension repo. Please run the following command to add it:" -ForegroundColor Red
Write-Host "+++++++++++++++++++++++++++++++++++++++++++++++++++++++" -ForegroundColor Red
Write-Host "azdev extension repo add $ExtensionRepo" -ForegroundColor Red
Write-Host "+++++++++++++++++++++++++++++++++++++++++++++++++++++++" -ForegroundColor Red
exit 1
}

# Fetch upstream/main branch
Write-Host "Fetching upstream/main branch..." -ForegroundColor Green
git fetch upstream main
if ($LASTEXITCODE -ne 0) {
Write-Host "Error: Failed to fetch upstream/main branch. Please run 'git remote add upstream https://github.com/Azure/azure-cli-extensions.git' first." -ForegroundColor Red
Write-Host "Error: Failed to fetch upstream/main branch. Please run the following command to add the upstream remote:" -ForegroundColor Red
Write-Host "+++++++++++++++++++++++++++++++++++++++++++++++++++++++" -ForegroundColor Red
Write-Host "git remote add upstream https://github.com/Azure/azure-cli-extensions.git" -ForegroundColor Red
Write-Host "+++++++++++++++++++++++++++++++++++++++++++++++++++++++" -ForegroundColor Red
exit 1
}

Expand All @@ -36,7 +48,10 @@ if ($AZURE_CLI_FOLDER) {
Write-Host "Fetching $AZURE_CLI_FOLDER upstream/dev branch..." -ForegroundColor Green
git -C $AZURE_CLI_FOLDER fetch upstream dev
if ($LASTEXITCODE -ne 0) {
Write-Host "Error: Failed to fetch $AZURE_CLI_FOLDER upstream/dev branch. Please run 'git -C $AZURE_CLI_FOLDER remote add upstream https://github.com/Azure/azure-cli.git' first." -ForegroundColor Red
Write-Host "Error: Failed to fetch $AZURE_CLI_FOLDER upstream/dev branch. Please run the following command to add the upstream remote:" -ForegroundColor Red
Write-Host "+++++++++++++++++++++++++++++++++++++++++++++++++++++++" -ForegroundColor Red
Write-Host "git -C $AZURE_CLI_FOLDER remote add upstream https://github.com/Azure/azure-cli.git" -ForegroundColor Red
Write-Host "+++++++++++++++++++++++++++++++++++++++++++++++++++++++" -ForegroundColor Red
exit 1
}

Expand Down
21 changes: 18 additions & 3 deletions .githooks/pre-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,35 @@ fi
# Get extension repo paths and join them with spaces
EXTENSIONS=$(azdev extension repo list -o tsv | tr '\n' ' ')

# Verify if current repo is in extension repo list
CURRENT_REPO=$(pwd)
if [[ ! "$EXTENSIONS" =~ "$CURRENT_REPO" ]]; then
printf "\033[0;31mThe current repo is not added as an extension repo. Please run the following command to add it:\033[0m\n"
printf "\033[0;31m+++++++++++++++++++++++++++++++++++++++++++++++++++++++\033[0m\n"
printf "\033[0;31mazdev extension repo add %s\033[0m\n" "$CURRENT_REPO"
printf "\033[0;31m+++++++++++++++++++++++++++++++++++++++++++++++++++++++\033[0m\n"
exit 1
fi

# Fetch upstream/main branch
printf "\033[0;32mFetching upstream/main branch...\033[0m\n"
git fetch upstream main
if [ $? -ne 0 ]; then
printf "\033[0;31mError: Failed to fetch upstream/main branch. Please run 'git remote add upstream https://github.com/Azure/azure-cli-extensions.git' first.\033[0m\n"
printf "\033[0;31mError: Failed to fetch upstream/main branch. Please run the following command to add the upstream remote:\033[0m\n"
printf "\033[0;31m+++++++++++++++++++++++++++++++++++++++++++++++++++++++\033[0m\n"
printf "\033[0;31mgit remote add upstream https://github.com/Azure/azure-cli-extensions.git\033[0m\n"
printf "\033[0;31m+++++++++++++++++++++++++++++++++++++++++++++++++++++++\033[0m\n"
exit 1
fi

if [ ! -z "$AZURE_CLI_FOLDER" ]; then
printf "\033[0;32mFetching %s upstream/dev branch...\033[0m\n" "$AZURE_CLI_FOLDER"
git -C "$AZURE_CLI_FOLDER" fetch upstream dev
if [ $? -ne 0 ]; then
printf "\033[0;31mError: Failed to fetch %s upstream/dev branch. Please run 'git -C %s remote add upstream https://github.com/Azure/azure-cli.git' first.\033[0m\n" "$AZURE_CLI_FOLDER" "$AZURE_CLI_FOLDER"
printf "\033[0;31mError: Failed to fetch %s upstream/dev branch. Please run the following command to add the upstream remote:\033[0m\n" "$AZURE_CLI_FOLDER"
printf "\033[0;31m+++++++++++++++++++++++++++++++++++++++++++++++++++++++\033[0m\n"
printf "\033[0;31mgit -C %s remote add upstream https://github.com/Azure/azure-cli.git\033[0m\n" "$AZURE_CLI_FOLDER"
printf "\033[0;31m+++++++++++++++++++++++++++++++++++++++++++++++++++++++\033[0m\n"
exit 1
fi

Expand Down Expand Up @@ -114,4 +130,3 @@ if [ ! -z "$AZURE_CLI_FOLDER" ]; then
fi
fi
exit 0

0 comments on commit 246dfdc

Please sign in to comment.