Repository: VirtusLab/git-machete
Pull request #1421 (2025-04-14 13:16:15)

Add missing check for `yq` answer when retargeting PRs/MRs from `traverse`


Patch:
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index 9ecfb6c..24d116c 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -2,6 +2,8 @@
 
 ## New in git-machete 3.34.1
 
+- fixed: `yq` answer to retargeting a PR/MR in `traverse` was treated just as `y`/`yes` (no quitting)
+
 ## New in git-machete 3.34.0
 
 - added: new `full-no-branches` and `up-only-no-branches` values to `machete.github.prDescriptionIntroStyle` and `machete.gitlab.mrDescriptionIntroStyle` git config keys
diff --git a/ci/checks/enforce-yq-check-for-each-y-yes-yq-check.sh b/ci/checks/enforce-yq-check-for-each-y-yes-yq-check.sh
new file mode 100755
index 0000000..fb0c2c3
--- /dev/null
+++ b/ci/checks/enforce-yq-check-for-each-y-yes-yq-check.sh
@@ -0,0 +1,16 @@
+#!/usr/bin/env bash
+
+set -e -o pipefail -u
+
+# xargs for stripping the leading spaces
+y_yes_yq_checks=$(git grep 'if ans in.*yq' '*.py' | wc -l | xargs)
+yq_checks=$(git grep 'if ans ==.*yq' '*.py' | wc -l | xargs)
+
+if [[ $yq_checks != "$y_yes_yq_checks" ]]; then
+  echo "In Python code, the number of checks for 'y', 'yes', 'yq' answers on interactive input ($y_yes_yq_checks)"
+  echo "is NOT equal to the number of narrower checks for 'yq' answer ($yq_checks)."
+  echo
+  echo "Does it mean that 'yq' is treated just as 'y' in some cases (without quitting)?"
+  echo "See https://github.com/VirtusLab/git-machete/pull/1421 for a sample fix."
+  exit 1
+fi
diff --git a/ci/checks/run-all-checks.sh b/ci/checks/run-all-checks.sh
index d2fb00a..25ba6da 100755
--- a/ci/checks/run-all-checks.sh
+++ b/ci/checks/run-all-checks.sh
@@ -25,6 +25,7 @@ enforce-mocking-only-whitelisted-methods.sh
 enforce-newline-at-eof.sh
 enforce-release-notes-up-to-date.sh
 enforce-shell-scripts-pass-shellcheck.sh
+enforce-yq-check-for-each-y-yes-yq-check.sh
 prohibit-bash-usages-from-python.sh
 prohibit-current-date-in-tests.sh
 prohibit-deploy-step-in-circleci.sh
diff --git a/docs/man/git-machete.1 b/docs/man/git-machete.1
index 5c15aae..eff9f8b 100644
--- a/docs/man/git-machete.1
+++ b/docs/man/git-machete.1
@@ -27,7 +27,7 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .in \\n[rst2man-indent\\n[rst2man-indent-level]]u
 ..
-.TH "GIT-MACHETE" "1" "Mar 31, 2025" "" "git-machete"
+.TH "GIT-MACHETE" "1" "Apr 14, 2025" "" "git-machete"
 .SH NAME
 git-machete \- git-machete 3.34.1
 .sp
diff --git a/git_machete/client.py b/git_machete/client.py
index c179375..2514aa4 100644
--- a/git_machete/client.py
+++ b/git_machete/client.py
@@ -1047,6 +1047,8 @@ class MacheteClient:
                             print(fmt(f'Description of {pr.display_text()} '
                                       f'(<b>{pr.head} {get_right_arrow()} {pr.base}</b>) has been updated'))
 
+                    if ans == 'yq':
+                        return
                 elif ans in ('q', 'quit'):
                     return
 


Test patch:
diff --git a/tests/test_traverse_gitlab.py b/tests/test_traverse_gitlab.py
index 7d42cd0..639eb35 100644
--- a/tests/test_traverse_gitlab.py
+++ b/tests/test_traverse_gitlab.py
@@ -193,8 +193,9 @@ class TestTraverseGitLab(BaseTest):
 
         mr2['target_branch'] = 'develop'
         check_out("build-chain")
+        self.patch_symbol(mocker, 'builtins.input', mock_input_returning("yq"))
         assert_success(
-            ["traverse", "-LWy"],
+            ["traverse", "-LW"],
             """
             Fetching origin...
 
@@ -212,17 +213,6 @@ class TestTraverseGitLab(BaseTest):
                   o-call-ws
 
             Branch build-chain has a different MR target (develop) in GitLab than in machete file (allow-ownership-link).
-            Retargeting MR !2 to allow-ownership-link...
+            Retarget MR !2 to allow-ownership-link? (y, N, q, yq)
             Target branch of MR !2 has been switched to allow-ownership-link
-
-              develop
-              |
-              o-allow-ownership-link
-                |
-                o-build-chain *  MR !2 (some_other_user)
-                  |
-                  o-call-ws
-
-            No successor of build-chain needs to be slid out or synced with upstream branch or remote; nothing left to update
-            Returned to the initial branch build-chain
             """)