Skip to content

Commit

Permalink
add rebase check
Browse files Browse the repository at this point in the history
  • Loading branch information
kairu-ms committed Nov 11, 2024
1 parent 5b6e687 commit 9df3931
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 24 deletions.
19 changes: 7 additions & 12 deletions .githooks/pre-push.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,17 @@ if ($LASTEXITCODE -ne 0) {
}

# Check if current branch needs rebasing
Write-Host "Checking if branch needs rebasing..." -ForegroundColor Green
$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') {
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
} else {
Write-Host "Continuing without rebase..." -ForegroundColor Yellow
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
}

# get the current branch name
Expand Down
19 changes: 7 additions & 12 deletions .githooks/pre-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,18 @@ if [ $? -ne 0 ]; then
fi

# Check if current branch needs rebasing
echo "\033[0;32mChecking if branch needs rebasing...\033[0m"
MERGE_BASE=$(git merge-base HEAD upstream/dev)
UPSTREAM_HEAD=$(git rev-parse upstream/dev)

if [ "$MERGE_BASE" != "$UPSTREAM_HEAD" ]; then
read -p "Your branch is not up to date with upstream/dev. Do you want to rebase? (Y/N) " response
if [[ "$response" =~ ^[Yy]$ ]]; then
git rebase upstream/dev
if [ $? -ne 0 ]; then
echo "\033[0;31mError: Rebase failed. Please resolve conflicts manually.\033[0m"
exit 1
fi
echo "\033[0;32mRunning azdev setup -c $AZURE_CLI_FOLDER\033[0m"
azdev setup -c "$AZURE_CLI_FOLDER"
else
echo "\033[0;33mContinuing without rebase...\033[0m"
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
fi
echo "\033[0;32mRunning azdev setup -c $AZURE_CLI_FOLDER\033[0m"
azdev setup -c "$AZURE_CLI_FOLDER"
fi

# get the current branch name
Expand Down

0 comments on commit 9df3931

Please sign in to comment.