Skip to content

Commit

Permalink
Add rebase upstream/dev warning.
Browse files Browse the repository at this point in the history
  • Loading branch information
kairu-ms committed Nov 11, 2024
1 parent ab49b4c commit 7e57b09
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 20 deletions.
31 changes: 18 additions & 13 deletions .githooks/pre-push.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ if ($editableLocation) {
exit 1
}

# Get extension repo paths and join them with spaces
$Extensions = (azdev extension repo list -o tsv) -join ' '

# Fetch upstream/dev branch
Write-Host "Fetching upstream/dev branch..." -ForegroundColor Green
git fetch upstream dev
Expand All @@ -35,21 +38,23 @@ if ($LASTEXITCODE -ne 0) {
$mergeBase = git merge-base HEAD upstream/dev
$upstreamHead = git rev-parse upstream/dev
if ($mergeBase -ne $upstreamHead) {
$response = Read-Host "Your branch is not up to date with upstream/dev. Do you want to rebase? (Y/N)"
if ($response -eq 'Y' -or $response -eq 'y') {
Write-Host "Rebasing branch to upstream/dev..." -ForegroundColor Green
git rebase upstream/dev
if ($LASTEXITCODE -ne 0) {
Write-Host "Error: Rebase failed. Please resolve conflicts manually." -ForegroundColor Red
exit 1
}
Write-Host "Running azdev setup -c $AZURE_CLI_FOLDER " -ForegroundColor Green
azdev setup -c $AZURE_CLI_FOLDER
Write-Host "Rebase completed. Please push with 'git push --force' again." -ForegroundColor Green
exit 1
Write-Host ""
Write-Host "Your branch is not up to date with upstream/dev. Please run the following commands to rebase and setup:" -ForegroundColor Yellow
Write-Host "+++++++++++++++++++++++++++++++++++++++++++++++++++++++" -ForegroundColor Yellow
Write-Host "git rebase upstream/dev" -ForegroundColor Yellow
if ($Extensions) {
Write-Host "azdev setup -c $AZURE_CLI_FOLDER -r $Extensions" -ForegroundColor Yellow
} else {
Write-Host "Continuing without rebase..." -ForegroundColor Yellow
Write-Host "azdev setup -c $AZURE_CLI_FOLDER" -ForegroundColor Yellow
}
Write-Host "+++++++++++++++++++++++++++++++++++++++++++++++++++++++" -ForegroundColor Yellow
Write-Host ""
Write-Host "You have 5 seconds to stop the push (Ctrl+C)..." -ForegroundColor Yellow
for ($i = 5; $i -gt 0; $i--) {
Write-Host "`rTime remaining: $i seconds..." -NoNewline -ForegroundColor Yellow
Start-Sleep -Seconds 1
}
Write-Host "`rContinuing without rebase..."
}

# get the current branch name
Expand Down
30 changes: 23 additions & 7 deletions .githooks/pre-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ else
exit 1
fi

# Get extension repo paths and join them with spaces
EXTENSIONS=$(azdev extension repo list -o tsv | tr '\n' ' ')

# Fetch upstream/dev branch
echo "\033[0;32mFetching upstream/dev branch...\033[0m"
git fetch upstream dev
Expand All @@ -33,14 +36,27 @@ MERGE_BASE=$(git merge-base HEAD upstream/dev)
UPSTREAM_HEAD=$(git rev-parse upstream/dev)

if [ "$MERGE_BASE" != "$UPSTREAM_HEAD" ]; then
echo "\033[0;32mRebasing branch to upstream/dev...\033[0m"
git rebase upstream/dev
if [ $? -ne 0 ]; then
echo "\033[0;31mError: Rebase failed. Please resolve conflicts manually.\033[0m"
exit 1
echo ""
echo "\033[1;33mYour branch is not up to date with upstream/dev. Please run the following commands to rebase and setup:\033[0m"
echo "\033[1;33m+++++++++++++++++++++++++++++++++++++++++++++++++++++++\033[0m"
echo "\033[1;33mgit rebase upstream/dev\033[0m"

# Get extension repo paths
EXTENSIONS=$(azdev extension repo list -o tsv | tr '\n' ' ')
if [ -n "$EXTENSIONS" ]; then
echo "\033[1;33mazdev setup -c $AZURE_CLI_FOLDER -r $EXTENSIONS\033[0m"
else
echo "\033[1;33mazdev setup -c $AZURE_CLI_FOLDER\033[0m"
fi
echo "\033[0;32mRunning azdev setup -c $AZURE_CLI_FOLDER\033[0m"
azdev setup -c "$AZURE_CLI_FOLDER"
echo "\033[1;33m+++++++++++++++++++++++++++++++++++++++++++++++++++++++\033[0m"
echo ""
echo "\033[1;33mYou have 5 seconds to stop the push (Ctrl+C)...\033[0m"

for i in {5..1}; do
echo -ne "\r\033[1;33mTime remaining: $i seconds...\033[0m"
sleep 1
done
echo -e "\r\033[1;33mContinuing without rebase...\033[0m"
fi

# get the current branch name
Expand Down

0 comments on commit 7e57b09

Please sign in to comment.