-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow
sno switch
to switch to a remote branch
- Loading branch information
Showing
3 changed files
with
187 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import pytest | ||
|
||
|
||
from sno.sno_repo import SnoRepo | ||
from sno.structs import CommitWithReference | ||
from sno.exceptions import NO_BRANCH, NO_COMMIT | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"working_copy", | ||
[ | ||
pytest.param(True, id="with-wc"), | ||
pytest.param(False, id="without-wc"), | ||
], | ||
) | ||
def test_checkout_branches(data_archive, cli_runner, chdir, tmp_path, working_copy): | ||
with data_archive("points") as remote_path: | ||
|
||
r = cli_runner.invoke(["checkout", "-b", "one"]) | ||
assert r.exit_code == 0, r.stderr | ||
r = cli_runner.invoke(["checkout", "HEAD^"]) | ||
assert r.exit_code == 0, r.stderr | ||
r = cli_runner.invoke(["switch", "--create", "two"]) | ||
assert r.exit_code == 0, r.stderr | ||
|
||
r = cli_runner.invoke(["checkout", "one", "-b", "three"]) | ||
assert r.exit_code == 0, r.stderr | ||
r = cli_runner.invoke(["switch", "two", "--create", "four"]) | ||
assert r.exit_code == 0, r.stderr | ||
|
||
repo = SnoRepo(remote_path) | ||
one = CommitWithReference.resolve(repo, "one") | ||
two = CommitWithReference.resolve(repo, "two") | ||
three = CommitWithReference.resolve(repo, "three") | ||
four = CommitWithReference.resolve(repo, "four") | ||
|
||
assert one.commit.hex == three.commit.hex | ||
assert two.commit.hex == four.commit.hex | ||
|
||
assert one.commit.hex != two.commit.hex | ||
|
||
wc_flag = "--checkout" if working_copy else "--no-checkout" | ||
r = cli_runner.invoke(["clone", remote_path, tmp_path, wc_flag]) | ||
repo = SnoRepo(tmp_path) | ||
|
||
head = CommitWithReference.resolve(repo, "HEAD") | ||
|
||
with chdir(tmp_path): | ||
|
||
r = cli_runner.invoke(["branch"]) | ||
assert r.exit_code == 0, r.stderr | ||
assert r.stdout.splitlines() == ["* four"] | ||
|
||
# Commit hex is not a branch name, can't be switched: | ||
r = cli_runner.invoke(["switch", head.commit.hex]) | ||
assert r.exit_code == NO_BRANCH, r.stderr | ||
# But can be checked out: | ||
r = cli_runner.invoke(["checkout", head.commit.hex]) | ||
assert r.exit_code == 0, r.stderr | ||
|
||
r = cli_runner.invoke(["checkout", "zero"]) | ||
assert r.exit_code == NO_COMMIT, r.stderr | ||
r = cli_runner.invoke(["switch", "zero"]) | ||
assert r.exit_code == NO_BRANCH, r.stderr | ||
|
||
r = cli_runner.invoke(["checkout", "one", "--no-guess"]) | ||
assert r.exit_code == NO_COMMIT, r.stderr | ||
r = cli_runner.invoke(["switch", "one", "--no-guess"]) | ||
assert r.exit_code == NO_BRANCH, r.stderr | ||
|
||
r = cli_runner.invoke(["checkout", "one"]) | ||
assert r.exit_code == 0, r.stderr | ||
assert ( | ||
r.stdout.splitlines()[0] | ||
== "Creating new branch 'one' to track 'origin/one'..." | ||
) | ||
assert ( | ||
CommitWithReference.resolve(repo, "HEAD").commit.hex == one.commit.hex | ||
) | ||
r = cli_runner.invoke(["switch", "two"]) | ||
assert r.exit_code == 0, r.stderr | ||
assert ( | ||
r.stdout.splitlines()[0] | ||
== "Creating new branch 'two' to track 'origin/two'..." | ||
) | ||
assert ( | ||
CommitWithReference.resolve(repo, "HEAD").commit.hex == two.commit.hex | ||
) | ||
|
||
r = cli_runner.invoke(["branch"]) | ||
assert r.exit_code == 0, r.stderr | ||
assert r.stdout.splitlines() == [" four", " one", "* two"] |