Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/subcommand/checkout_subcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ void checkout_subcommand::run()
update_head(repo, annotated_commit, target_name);

std::cout << "Switched to a new branch '" << target_name << "'" << std::endl;
return;
}
else if (!pathspecs.empty())
{
Expand Down
8 changes: 5 additions & 3 deletions test/conftest_lite.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@
STDERR_FILE = "stderr.txt"

# Command line that writes the exit code of the previous command line and the shell's cwd to the
# terminal, as lines such as '?=0' and 'PWD=/drive'.
# terminal, as lines such as '?=0' and 'PWD=/drive'. Some versions of coreutils env quote the
# '?' name as in "'?'=0", so allow an optional character either side of it.
# Quote the grep pattern as cockle treats an unquoted '?' as a glob wildcard.
EXIT_CODE_AND_PWD_LINE = "env | grep -E '^(\\?|PWD)='"
EXIT_CODE_AND_PWD_LINE = "env | grep -E '^(.?\\?.?|PWD)='"

# Collect the output of the open terminal so that we can tell when a command line has finished.
COLLECT_OUTPUT_JS = """
Expand Down Expand Up @@ -230,7 +231,8 @@ def read_exit_code_and_pwd(page: Page) -> tuple[int | None, str]:
output = run_line(page, EXIT_CODE_AND_PWD_LINE)
# Remove ANSI escape sequences such as colours, as grep is aliased to 'grep --color=auto'.
output = re.sub(r"\x1b\[[0-9;]*[A-Za-z]", "", output)
returncode = re.search(r"^\?=(-?\d+)\s*$", output, re.MULTILINE)
# The '?' name may or may not be quoted, depending on the version of coreutils env.
returncode = re.search(r"^'?\?'?=(-?\d+)\s*$", output, re.MULTILINE)
pwd = re.search(r"^PWD=(.*?)\s*$", output, re.MULTILINE)
if pwd is None:
raise RuntimeError(f"Unable to read PWD from terminal output: {output!r}")
Expand Down
2 changes: 2 additions & 0 deletions test/test_checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def test_checkout_b(repo_init_with_commit, git2cpp_path, tmp_path):
p_checkout = subprocess.run(checkout_cmd, capture_output=True, cwd=tmp_path, text=True)
assert p_checkout.returncode == 0
assert "Switched to a new branch 'foregone'" in p_checkout.stdout
assert "Switched to branch 'foregone'" not in p_checkout.stdout

branch_cmd = [git2cpp_path, "branch"]
p_branch = subprocess.run(branch_cmd, capture_output=True, cwd=tmp_path, text=True)
Expand Down Expand Up @@ -65,6 +66,7 @@ def test_checkout_B_force_create(repo_init_with_commit, git2cpp_path, tmp_path):
p_checkout = subprocess.run(checkout_cmd, capture_output=True, cwd=tmp_path, text=True)
assert p_checkout.returncode == 0
assert "Switched to a new branch 'resetme'" in p_checkout.stdout
assert "Switched to branch 'resetme'" not in p_checkout.stdout

# Verify we're on the branch
branch_cmd = [git2cpp_path, "branch"]
Expand Down
Loading