From 7782884a8319dc3be6664d25c56fb5fd284d5b0d Mon Sep 17 00:00:00 2001 From: ZelinWang Date: Thu, 12 Dec 2024 11:35:08 +0800 Subject: [PATCH 01/10] update githooks --- .githooks/pre-push.ps1 | 49 ++++++++++++++++++++--------- .githooks/pre-push.sh | 70 ++++++++++++++++++------------------------ 2 files changed, 65 insertions(+), 54 deletions(-) diff --git a/.githooks/pre-push.ps1 b/.githooks/pre-push.ps1 index 329e4f9053f..8c11d5488ee 100644 --- a/.githooks/pre-push.ps1 +++ b/.githooks/pre-push.ps1 @@ -39,22 +39,43 @@ $mergeBase = git merge-base HEAD upstream/dev $upstreamHead = git rev-parse upstream/dev if ($mergeBase -ne $upstreamHead) { 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 "azdev setup -c $AZURE_CLI_FOLDER" -ForegroundColor Yellow + Write-Host "Your branch is not up to date with upstream/dev." -ForegroundColor Yellow + Write-Host "Would you like to automatically rebase and setup? [Y/n]" -ForegroundColor Yellow + + try { + $reader = [System.IO.StreamReader]::new("CON") + $input = $reader.ReadLine() + } catch { + Write-Host "Error reading input. Aborting push..." -ForegroundColor Red + exit 1 } - 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 + + if ($input -match '^[Yy]$') { + Write-Host "Rebasing with upstream/dev..." -ForegroundColor Green + git rebase upstream/dev + if ($LASTEXITCODE -ne 0) { + Write-Host "Rebase failed. Please resolve conflicts and try again." -ForegroundColor Red + exit 1 + } + Write-Host "Rebase completed successfully." -ForegroundColor Green + + Write-Host "Running azdev setup..." -ForegroundColor Green + if ($Extensions) { + azdev setup -c $AZURE_CLI_FOLDER -r $Extensions + } else { + azdev setup -c $AZURE_CLI_FOLDER + } + if ($LASTEXITCODE -ne 0) { + Write-Host "azdev setup failed. Please check your environment." -ForegroundColor Red + exit 1 + } + Write-Host "Setup completed successfully." -ForegroundColor Green + } elseif ($input -match '^[Nn]$') { + Write-Host "Skipping rebase and setup. Continue push..." -ForegroundColor Red + } else { + Write-Host "Invalid input. Aborting push..." -ForegroundColor Red + exit 1 } - Write-Host "`rContinuing without rebase..." } # get the current branch name diff --git a/.githooks/pre-push.sh b/.githooks/pre-push.sh index 19362cddd2e..7b028cafaa3 100644 --- a/.githooks/pre-push.sh +++ b/.githooks/pre-push.sh @@ -37,32 +37,39 @@ UPSTREAM_HEAD=$(git rev-parse upstream/dev) if [ "$MERGE_BASE" != "$UPSTREAM_HEAD" ]; then printf "\n" - printf "\033[1;33mYour branch is not up to date with upstream/dev. Please run the following commands to rebase and setup:\033[0m\n" - printf "\033[1;33m+++++++++++++++++++++++++++++++++++++++++++++++++++++++\033[0m\n" - printf "\033[1;33mgit rebase upstream/dev\033[0m\n" - - # Get extension repo paths - EXTENSIONS=$(azdev extension repo list -o tsv | tr '\n' ' ') - if [ -n "$EXTENSIONS" ]; then - printf "\033[1;33mazdev setup -c %s -r %s\033[0m\n" "$AZURE_CLI_FOLDER" "$EXTENSIONS" + printf "\033[1;33mYour branch is not up to date with upstream/dev.\033[0m\n" + printf "\033[1;33mWould you like to automatically rebase and setup? [Y/n]\033[0m\n" + + read -r INPUT + if [[ "$INPUT" =~ ^[Yy]$ ]]; then + printf "\033[0;32mRebasing with upstream/dev...\033[0m\n" + git rebase upstream/dev + if [ $? -ne 0 ]; then + printf "\033[0;31mRebase failed. Please resolve conflicts and try again.\033[0m\n" + exit 1 + fi + printf "\033[0;32mRebase completed successfully.\033[0m\n" + + printf "\033[0;32mRunning azdev setup...\033[0m\n" + if [ -n "$EXTENSIONS" ]; then + azdev setup -c "$AZURE_CLI_FOLDER" -r "$EXTENSIONS" + else + azdev setup -c "$AZURE_CLI_FOLDER" + fi + if [ $? -ne 0 ]; then + printf "\033[0;31mazdev setup failed. Please check your environment.\033[0m\n" + exit 1 + fi + printf "\033[0;32mSetup completed successfully.\033[0m\n" + elif [[ "$INPUT" =~ ^[Nn]$ ]]; then + printf "\r\033[K\033[1;33mSkipping rebase and setup. Continue push...\033[0m\n" else - printf "\033[1;33mazdev setup -c %s\033[0m\n" "$AZURE_CLI_FOLDER" + printf "\033[0;31mInvalid input. Aborting push...\033[0m\n" + exit 1 fi - printf "\033[1;33m+++++++++++++++++++++++++++++++++++++++++++++++++++++++\033[0m\n" - printf "\n" - printf "\033[1;33mYou have 5 seconds to stop the push (Ctrl+C)...\033[0m\n" - - # Using a C-style for loop instead of seq - i=5 - while [ $i -ge 1 ]; do - printf "\r\033[K\033[1;33mTime remaining: %d seconds...\033[0m" $i - sleep 1 - i=$((i-1)) - done - printf "\r\033[K\033[1;33mContinuing without rebase...\033[0m\n" fi -# get the current branch name +# Get the current branch name CURRENT_BRANCH=$(git branch --show-current) # Run command azdev lint @@ -93,26 +100,9 @@ if [ $? -ne 0 ]; then printf "\033[0;31mError: azdev test check failed.\033[0m\n" exit 1 else - # remove the test_results.xml file + # Remove the test_results.xml file rm -f test_results.xml fi printf "\033[0;32mPre-push hook passed.\033[0m\n" - -if [ "$MERGE_BASE" != "$UPSTREAM_HEAD" ]; then - printf "\n" - printf "\033[1;33mYour branch is not up to date with upstream/dev. Please run the following commands to rebase and setup:\033[0m\n" - printf "\033[1;33m+++++++++++++++++++++++++++++++++++++++++++++++++++++++\033[0m\n" - printf "\033[1;33mgit rebase upstream/dev\033[0m\n" - - # Get extension repo paths - EXTENSIONS=$(azdev extension repo list -o tsv | tr '\n' ' ') - if [ -n "$EXTENSIONS" ]; then - printf "\033[1;33mazdev setup -c %s -r %s\033[0m\n" "$AZURE_CLI_FOLDER" "$EXTENSIONS" - else - printf "\033[1;33mazdev setup -c %s\033[0m\n" "$AZURE_CLI_FOLDER" - fi - printf "\033[1;33m+++++++++++++++++++++++++++++++++++++++++++++++++++++++\033[0m\n" -fi exit 0 - From ab4b3840d0e7164d55b8487cb228ef2157277341 Mon Sep 17 00:00:00 2001 From: ZelinWang Date: Thu, 12 Dec 2024 15:13:23 +0800 Subject: [PATCH 02/10] update githooks --- .githooks/pre-push.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.githooks/pre-push.sh b/.githooks/pre-push.sh index 7b028cafaa3..8bdb7b1d143 100644 --- a/.githooks/pre-push.sh +++ b/.githooks/pre-push.sh @@ -40,8 +40,8 @@ if [ "$MERGE_BASE" != "$UPSTREAM_HEAD" ]; then printf "\033[1;33mYour branch is not up to date with upstream/dev.\033[0m\n" printf "\033[1;33mWould you like to automatically rebase and setup? [Y/n]\033[0m\n" - read -r INPUT - if [[ "$INPUT" =~ ^[Yy]$ ]]; then + read -r INPUT < /dev/tty + if [ "$INPUT" = "Y" ] || [ "$INPUT" = "y" ]; then printf "\033[0;32mRebasing with upstream/dev...\033[0m\n" git rebase upstream/dev if [ $? -ne 0 ]; then @@ -61,7 +61,7 @@ if [ "$MERGE_BASE" != "$UPSTREAM_HEAD" ]; then exit 1 fi printf "\033[0;32mSetup completed successfully.\033[0m\n" - elif [[ "$INPUT" =~ ^[Nn]$ ]]; then + elif [ "$INPUT" = "N" ] || [ "$INPUT" = "n" ]; then printf "\r\033[K\033[1;33mSkipping rebase and setup. Continue push...\033[0m\n" else printf "\033[0;31mInvalid input. Aborting push...\033[0m\n" From 59842df004ce97afef44959fdf031df4d88e9fe5 Mon Sep 17 00:00:00 2001 From: ZelinWang Date: Thu, 12 Dec 2024 15:44:00 +0800 Subject: [PATCH 03/10] update githooks --- .githooks/pre-push.ps1 | 15 ++------------- .githooks/pre-push.sh | 2 ++ 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/.githooks/pre-push.ps1 b/.githooks/pre-push.ps1 index 8c11d5488ee..15096096e86 100644 --- a/.githooks/pre-push.ps1 +++ b/.githooks/pre-push.ps1 @@ -58,6 +58,7 @@ if ($mergeBase -ne $upstreamHead) { exit 1 } Write-Host "Rebase completed successfully." -ForegroundColor Green + $mergeBase = git merge-base HEAD upstream/dev Write-Host "Running azdev setup..." -ForegroundColor Green if ($Extensions) { @@ -113,18 +114,6 @@ if ($LASTEXITCODE -ne 0) { Remove-Item test_results.xml } +Write-Host "If you want to skip that, run add '--no-verify' in the end of 'git push' command." -ForegroundColor Yellow Write-Host "Pre-push hook passed." -ForegroundColor Green - -if ($mergeBase -ne $upstreamHead) { - Write-Host "" - Write-Host "Your branch is not up to date with upstream/dev. Please run the following commands to rebase code 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 "azdev setup -c $AZURE_CLI_FOLDER" -ForegroundColor Yellow - } - Write-Host "+++++++++++++++++++++++++++++++++++++++++++++++++++++++" -ForegroundColor Yellow -} exit 0 diff --git a/.githooks/pre-push.sh b/.githooks/pre-push.sh index 8bdb7b1d143..3ff12dac899 100644 --- a/.githooks/pre-push.sh +++ b/.githooks/pre-push.sh @@ -49,6 +49,7 @@ if [ "$MERGE_BASE" != "$UPSTREAM_HEAD" ]; then exit 1 fi printf "\033[0;32mRebase completed successfully.\033[0m\n" + MERGE_BASE=$(git merge-base HEAD upstream/dev) printf "\033[0;32mRunning azdev setup...\033[0m\n" if [ -n "$EXTENSIONS" ]; then @@ -104,5 +105,6 @@ else rm -f test_results.xml fi +printf "\033[0;32mIf you want to skip that, run add '--no-verify' in the end of 'git push' command.\033[0m\n" printf "\033[0;32mPre-push hook passed.\033[0m\n" exit 0 From 401ed269147677c3451e5b33874b4e6c16d7f03a Mon Sep 17 00:00:00 2001 From: ZelinWang Date: Fri, 13 Dec 2024 10:00:51 +0800 Subject: [PATCH 04/10] update githooks --- .githooks/pre-push.ps1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.githooks/pre-push.ps1 b/.githooks/pre-push.ps1 index 15096096e86..9b1da5f77ca 100644 --- a/.githooks/pre-push.ps1 +++ b/.githooks/pre-push.ps1 @@ -37,6 +37,7 @@ if ($LASTEXITCODE -ne 0) { # Check if current branch needs rebasing $mergeBase = git merge-base HEAD upstream/dev $upstreamHead = git rev-parse upstream/dev +Write-Host "Initial mergeBase: $mergeBase" -ForegroundColor Cyan if ($mergeBase -ne $upstreamHead) { Write-Host "" Write-Host "Your branch is not up to date with upstream/dev." -ForegroundColor Yellow @@ -59,6 +60,7 @@ if ($mergeBase -ne $upstreamHead) { } Write-Host "Rebase completed successfully." -ForegroundColor Green $mergeBase = git merge-base HEAD upstream/dev + Write-Host "Updated mergeBase: $mergeBase" -ForegroundColor Cyan Write-Host "Running azdev setup..." -ForegroundColor Green if ($Extensions) { From 085fbb78fd89a1e9eba74906db27c939927de29d Mon Sep 17 00:00:00 2001 From: ZelinWang Date: Fri, 13 Dec 2024 10:59:03 +0800 Subject: [PATCH 05/10] update githooks --- .githooks/pre-push.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.githooks/pre-push.sh b/.githooks/pre-push.sh index 3ff12dac899..86d81e6182c 100644 --- a/.githooks/pre-push.sh +++ b/.githooks/pre-push.sh @@ -34,6 +34,7 @@ fi # Check if current branch needs rebasing MERGE_BASE=$(git merge-base HEAD upstream/dev) UPSTREAM_HEAD=$(git rev-parse upstream/dev) +printf "\033[0;36mInitial mergeBase: %s\033[0m\n" "$MERGE_BASE" if [ "$MERGE_BASE" != "$UPSTREAM_HEAD" ]; then printf "\n" @@ -50,6 +51,7 @@ if [ "$MERGE_BASE" != "$UPSTREAM_HEAD" ]; then fi printf "\033[0;32mRebase completed successfully.\033[0m\n" MERGE_BASE=$(git merge-base HEAD upstream/dev) + printf "\033[0;36mUpdated mergeBase: %s\033[0m\n" "$MERGE_BASE" printf "\033[0;32mRunning azdev setup...\033[0m\n" if [ -n "$EXTENSIONS" ]; then @@ -108,3 +110,4 @@ fi printf "\033[0;32mIf you want to skip that, run add '--no-verify' in the end of 'git push' command.\033[0m\n" printf "\033[0;32mPre-push hook passed.\033[0m\n" exit 0 + From 09d0cba3a7e6be8f70be63d725dceb818cf3fd5d Mon Sep 17 00:00:00 2001 From: ZelinWang Date: Fri, 13 Dec 2024 11:28:01 +0800 Subject: [PATCH 06/10] update githooks --- .githooks/pre-push.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.githooks/pre-push.sh b/.githooks/pre-push.sh index 86d81e6182c..0484b29e799 100644 --- a/.githooks/pre-push.sh +++ b/.githooks/pre-push.sh @@ -21,7 +21,7 @@ else fi # Get extension repo paths and join them with spaces -EXTENSIONS=$(azdev extension repo list -o tsv | tr '\n' ' ') +EXTENSIONS=$(azdev extension repo list -o tsv | tr '\n' ' ' | sed 's/ $//') # Fetch upstream/dev branch printf "\033[0;32mFetching upstream/dev branch...\033[0m\n" From 52b549b89472dadce3a7f692f0ffecd67e63fe70 Mon Sep 17 00:00:00 2001 From: ZelinWang Date: Fri, 13 Dec 2024 11:30:57 +0800 Subject: [PATCH 07/10] update githooks --- .githooks/pre-push.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/.githooks/pre-push.ps1 b/.githooks/pre-push.ps1 index 9b1da5f77ca..b851c82ea37 100644 --- a/.githooks/pre-push.ps1 +++ b/.githooks/pre-push.ps1 @@ -38,6 +38,7 @@ if ($LASTEXITCODE -ne 0) { $mergeBase = git merge-base HEAD upstream/dev $upstreamHead = git rev-parse upstream/dev Write-Host "Initial mergeBase: $mergeBase" -ForegroundColor Cyan + if ($mergeBase -ne $upstreamHead) { Write-Host "" Write-Host "Your branch is not up to date with upstream/dev." -ForegroundColor Yellow From ffa2ecda24a8db67fb7396128ffc9194e34cdd68 Mon Sep 17 00:00:00 2001 From: ZelinWang Date: Fri, 13 Dec 2024 11:36:28 +0800 Subject: [PATCH 08/10] update githooks --- .githooks/pre-push.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.githooks/pre-push.sh b/.githooks/pre-push.sh index 0484b29e799..9274a70fcba 100644 --- a/.githooks/pre-push.sh +++ b/.githooks/pre-push.sh @@ -107,7 +107,7 @@ else rm -f test_results.xml fi -printf "\033[0;32mIf you want to skip that, run add '--no-verify' in the end of 'git push' command.\033[0m\n" -printf "\033[0;32mPre-push hook passed.\033[0m\n" +printf "\033[0;32mIf you want to skip that, run add '--no-verify' in the end of 'git push' command.\033[0m\r\n" +printf "\033[0;32mPre-push hook passed.\033[0m\r\n" exit 0 From ed34307d5ceb3703c0adf00788a905ea606c53a0 Mon Sep 17 00:00:00 2001 From: ZelinWang Date: Fri, 13 Dec 2024 11:38:47 +0800 Subject: [PATCH 09/10] update githooks --- .githooks/pre-push.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.githooks/pre-push.sh b/.githooks/pre-push.sh index 9274a70fcba..01fe6586376 100644 --- a/.githooks/pre-push.sh +++ b/.githooks/pre-push.sh @@ -107,7 +107,8 @@ else rm -f test_results.xml fi -printf "\033[0;32mIf you want to skip that, run add '--no-verify' in the end of 'git push' command.\033[0m\r\n" -printf "\033[0;32mPre-push hook passed.\033[0m\r\n" +printf "\033[0;32m+++++++++++++++++++++++++++++++++++++++++++++++++++++++\033[0m\n" +printf "\033[0;32mIf you want to skip that, run add '--no-verify' in the end of 'git push' command.\033[0m\n" +printf "\033[0;32mPre-push hook passed.\033[0m\n" exit 0 From 7d4f4446ceb6700d567de4ab090078aaa17d8709 Mon Sep 17 00:00:00 2001 From: ZelinWang Date: Fri, 13 Dec 2024 11:39:58 +0800 Subject: [PATCH 10/10] update githooks --- .githooks/pre-push.ps1 | 1 - .githooks/pre-push.sh | 2 -- 2 files changed, 3 deletions(-) diff --git a/.githooks/pre-push.ps1 b/.githooks/pre-push.ps1 index b851c82ea37..ba0fc23d76a 100644 --- a/.githooks/pre-push.ps1 +++ b/.githooks/pre-push.ps1 @@ -117,6 +117,5 @@ if ($LASTEXITCODE -ne 0) { Remove-Item test_results.xml } -Write-Host "If you want to skip that, run add '--no-verify' in the end of 'git push' command." -ForegroundColor Yellow Write-Host "Pre-push hook passed." -ForegroundColor Green exit 0 diff --git a/.githooks/pre-push.sh b/.githooks/pre-push.sh index 01fe6586376..5377abab367 100644 --- a/.githooks/pre-push.sh +++ b/.githooks/pre-push.sh @@ -107,8 +107,6 @@ else rm -f test_results.xml fi -printf "\033[0;32m+++++++++++++++++++++++++++++++++++++++++++++++++++++++\033[0m\n" -printf "\033[0;32mIf you want to skip that, run add '--no-verify' in the end of 'git push' command.\033[0m\n" printf "\033[0;32mPre-push hook passed.\033[0m\n" exit 0