Bird
Raised Fist0
Gitdevops~20 mins

git bisect run for automated bisect - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Git Bisect Automation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of git bisect run with a simple test script
You run git bisect run ./test_script.sh where test_script.sh exits 0 if the commit is good and 1 if bad. What will be the final output after bisect completes?
Git
git bisect start
# Assume bad commit is HEAD, good commit is v1.0
# test_script.sh returns 0 on good, 1 on bad
# git bisect run ./test_script.sh
A
Bisecting: 3 revisions left to test after this (roughly 2 steps)
[commit_hash] Commit message

Bisecting incomplete, manual intervention needed
B
Bisecting: 3 revisions left to test after this (roughly 2 steps)
[commit_hash] Commit message

No bad commits found
C
Bisecting: 3 revisions left to test after this (roughly 2 steps)
[commit_hash] Commit message

<commit_hash> is the first bad commit
D
error: ./test_script.sh: command not found
Bisecting stopped
Attempts:
2 left
💡 Hint
Think about what git bisect run does when the test script returns 0 or 1.
🧠 Conceptual
intermediate
1:30remaining
Purpose of git bisect run
What is the main purpose of using git bisect run in a git repository?
ATo create a new branch and switch to it
BTo automatically find the first bad commit by running a test script on each commit
CTo merge two branches automatically without conflicts
DTo reset the repository to the last commit
Attempts:
2 left
💡 Hint
Think about how automation helps in finding bugs in commits.
❓ Troubleshoot
advanced
2:00remaining
Why does git bisect run stop unexpectedly?
You run git bisect run ./test_script.sh but bisect stops after a few commits with the message: error: test_script.sh: command not found. What is the most likely cause?
AThe test script is not executable or not in the PATH during bisect
BThe repository has no bad commits
CThe git bisect command is deprecated
DThe test script returns exit code 0
Attempts:
2 left
💡 Hint
Check the permissions and location of the test script.
🔀 Workflow
advanced
2:30remaining
Correct sequence to use git bisect run
What is the correct sequence of commands to use git bisect run to find a bad commit?
A1,3,2,4
B3,1,2,4
C2,1,3,4
D1,2,3,4
Attempts:
2 left
💡 Hint
Start bisect, mark bad, mark good, then run the test script.
✅ Best Practice
expert
3:00remaining
Best practice for writing a test script for git bisect run
Which of the following is the best practice when writing a test script to use with git bisect run?
AExit with 0 if the commit is good, 1 if bad, and 125 if the test cannot be run
BAlways exit with 0 regardless of test result
CPrint the commit hash and exit with 2 on bad commits
DUse interactive prompts to ask the user if the commit is good or bad
Attempts:
2 left
💡 Hint
Check git bisect run exit code conventions.

Practice

(1/5)
1. What is the main purpose of git bisect run in debugging?
easy
A. To manually mark commits as good or bad during bisect
B. To automate the process of finding the first bad commit using a test script
C. To reset the repository to the latest commit
D. To merge two branches automatically

Solution

  1. Step 1: Understand the role of git bisect run

    This command automates the bisect process by running a test script on each commit to check if it is good or bad.
  2. Step 2: Compare with other options

    Manual marking is done without run, resetting or merging are unrelated to bisect automation.
  3. Final Answer:

    To automate the process of finding the first bad commit using a test script -> Option B
  4. Quick Check:

    Automation with test script = B [OK]
Hint: Remember: git bisect run automates testing commits [OK]
Common Mistakes:
  • Confusing manual bisect with automated bisect
  • Thinking it resets or merges branches
  • Assuming it marks commits without a script
2. Which of the following is the correct syntax to start an automated bisect with a test script named test.sh?
easy
A. git bisect start test.sh
B. git bisect automate test.sh
C. git bisect run ./test.sh
D. git bisect test ./test.sh

Solution

  1. Step 1: Recall the correct command structure

    The correct syntax to run a test script during bisect is git bisect run <script>.
  2. Step 2: Match options with syntax

    Only git bisect run ./test.sh matches the correct syntax with the script path ./test.sh.
  3. Final Answer:

    git bisect run ./test.sh -> Option C
  4. Quick Check:

    Correct syntax = D [OK]
Hint: Use git bisect run <script> to automate tests [OK]
Common Mistakes:
  • Using 'start' instead of 'run'
  • Omitting './' before script name
  • Using incorrect verbs like 'automate' or 'test'
3. Given the following test script test.sh that exits with 1 if a file bug.txt exists, else exits 0:
#!/bin/sh
if [ -f bug.txt ]; then
  exit 1
else
  exit 0
fi

What will git bisect run ./test.sh interpret if bug.txt is present in a commit?
medium
A. The commit will be skipped
B. The commit is good
C. The bisect will stop with an error
D. The commit is bad

Solution

  1. Step 1: Understand exit codes in test script

    The script exits with 1 if bug.txt exists, which means failure (bad commit).
  2. Step 2: Interpret exit code in bisect context

    git bisect run treats exit code 0 as good and non-zero as bad, so exit 1 means bad commit.
  3. Final Answer:

    The commit is bad -> Option D
  4. Quick Check:

    Exit 1 = bad commit = A [OK]
Hint: Exit 0 means good; non-zero means bad in bisect scripts [OK]
Common Mistakes:
  • Confusing exit 1 as good
  • Assuming script errors stop bisect
  • Thinking bisect skips commits on exit 1
4. You run git bisect run ./test.sh but it stops with the error: ./test.sh: Permission denied. What is the most likely cause?
medium
A. The test script is missing execute permission
B. The bisect command is misspelled
C. The repository is not initialized
D. The test script returns exit code 0

Solution

  1. Step 1: Analyze the error message

    The error Permission denied means the shell cannot run the script, often due to missing execute permission.
  2. Step 2: Check other options

    Bisect command spelling or repo initialization would cause different errors; exit code 0 does not cause this error.
  3. Final Answer:

    The test script is missing execute permission -> Option A
  4. Quick Check:

    Missing execute permission = A [OK]
Hint: Make script executable with chmod +x before running [OK]
Common Mistakes:
  • Ignoring file permissions
  • Assuming bisect command typo
  • Thinking exit code causes command not found
5. You want to find the first bad commit that introduced a bug detected by a Python test script check_bug.py. The script returns exit code 0 if no bug and 1 if bug found. Which sequence of commands correctly automates bisecting?
hard
A. git bisect start; git bisect bad <bad_commit>; git bisect good <good_commit>; git bisect run python3 check_bug.py
B. git bisect start; git bisect good; git bisect bad <bad_commit>; git bisect run python3 check_bug.py
C. git bisect start; git bisect bad; git bisect good <good_commit>; git bisect run python3 check_bug.py
D. git bisect start; git bisect good <bad_commit>; git bisect bad <good_commit>; git bisect run python3 check_bug.py

Solution

  1. Step 1: Understand bisect start sequence

    You must start bisect, mark a known bad commit first, then a known good commit, then run the test script.
  2. Step 2: Match the correct order

    git bisect start; git bisect bad <bad_commit>; git bisect good <good_commit>; git bisect run python3 check_bug.py correctly marks bad commit first, then good commit, then runs the script with Python.
  3. Final Answer:

    git bisect start; git bisect bad <bad_commit>; git bisect good <good_commit>; git bisect run python3 check_bug.py -> Option A
  4. Quick Check:

    Bad then good then run script = C [OK]
Hint: Always mark bad commit first, then good, then run script [OK]
Common Mistakes:
  • Swapping good and bad commit order
  • Forgetting to start bisect
  • Running script before marking commits
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard