forked from xonsh/xonsh
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Fossil SCM branch names in vc.py. (xonsh#5046)
Add support for Fossil VCS in vc.py. The prompt now shows the currently active Fossil branch, while inside a Fossil checkout.
- Loading branch information
1 parent
237e231
commit cb95f0e
Showing
3 changed files
with
108 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
**Added:** | ||
|
||
* Display the current branch of Fossil VCS checkouts in the prompt, | ||
similar to git and hg. | ||
|
||
**Changed:** | ||
|
||
* <news item> | ||
|
||
**Deprecated:** | ||
|
||
* <news item> | ||
|
||
**Removed:** | ||
|
||
* <news item> | ||
|
||
**Fixed:** | ||
|
||
* <news item> | ||
|
||
**Security:** | ||
|
||
* <news item> |
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import os | ||
import subprocess as sp | ||
import textwrap | ||
from typing import Dict, List | ||
from pathlib import Path | ||
from unittest.mock import Mock | ||
|
||
|
@@ -8,7 +10,19 @@ | |
from xonsh.prompt import vc | ||
|
||
# Xonsh interaction with version control systems. | ||
VC_BRANCH = {"git": {"master", "main"}, "hg": {"default"}} | ||
VC_BRANCH = { | ||
"git": {"master", "main"}, | ||
"hg": {"default"}, | ||
"fossil": {"trunk"}, | ||
} | ||
VC_INIT: Dict[str, List[List[str]]] = { | ||
# A sequence of commands required to initialize a repository | ||
"git": [["init"]], | ||
"hg": [["init"]], | ||
# Fossil "init" creates a central repository file with the given name, | ||
# "open" creates the working directory at another, arbitrary location. | ||
"fossil": [["init", "test.fossil"], ["open", "test.fossil"]] | ||
} | ||
|
||
|
||
@pytest.fixture(params=VC_BRANCH.keys()) | ||
|
@@ -20,28 +34,32 @@ def repo(request, tmpdir_factory): | |
temp_dir = Path(tmpdir_factory.mktemp("dir")) | ||
os.chdir(temp_dir) | ||
try: | ||
sp.call([vc, "init"]) | ||
for init_command in VC_INIT[vc]: | ||
sp.call([vc] + init_command) | ||
except FileNotFoundError: | ||
pytest.skip(f"cannot find {vc} executable") | ||
if vc == "git": | ||
git_config = temp_dir / ".git/config" | ||
git_config.write_text( | ||
""" | ||
[user] | ||
name = me | ||
email = [email protected] | ||
[init] | ||
defaultBranch = main | ||
""" | ||
) | ||
|
||
# git needs at least one commit | ||
Path("test-file").touch() | ||
sp.call(["git", "add", "test-file"]) | ||
sp.call(["git", "commit", "-m", "test commit"]) | ||
_init_git_repository(temp_dir) | ||
return {"vc": vc, "dir": temp_dir} | ||
|
||
|
||
def _init_git_repository(temp_dir): | ||
git_config = temp_dir / ".git/config" | ||
git_config.write_text(textwrap.dedent( | ||
"""\ | ||
[user] | ||
name = me | ||
email = [email protected] | ||
[init] | ||
defaultBranch = main | ||
""" | ||
)) | ||
# git needs at least one commit | ||
Path("test-file").touch() | ||
sp.call(["git", "add", "test-file"]) | ||
sp.call(["git", "commit", "-m", "test commit"]) | ||
|
||
|
||
@pytest.fixture | ||
def set_xenv(xession, monkeypatch): | ||
def _wrapper(path): | ||
|
@@ -52,8 +70,15 @@ def _wrapper(path): | |
|
||
|
||
def test_test_repo(repo): | ||
test_vc_dir = repo["dir"] / ".{}".format(repo["vc"]) | ||
assert test_vc_dir.is_dir() | ||
if repo["vc"] == "fossil": | ||
# Fossil stores the check-out meta-data in a special file within the open check-out. | ||
# At least one of these below must exist | ||
metadata_file_names = {".fslckout", "_FOSSIL_"} # .fslckout on Unix, _FOSSIL_ on Windows | ||
existing_files = set(file.name for file in repo["dir"].iterdir()) | ||
assert existing_files.intersection(metadata_file_names) | ||
else: | ||
test_vc_dir = repo["dir"] / ".{}".format(repo["vc"]) | ||
assert test_vc_dir.is_dir() | ||
if repo["vc"] == "git": | ||
test_file = repo["dir"] / "test-file" | ||
assert test_file.exists() | ||
|
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