-
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.
Merge pull request #1 from Svtter/fix/checker-bug
Fix/checker-bug
- Loading branch information
Showing
6 changed files
with
162 additions
and
5 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,13 +1,16 @@ | ||
import os | ||
|
||
|
||
def check_clean(): | ||
def check_clean(folder: str = "."): | ||
# 检查git仓库是否有未提交的更改 | ||
result = os.system("git status --porcelain") | ||
if result != 0: | ||
print("错误: 无法获取git状态") | ||
os.chdir(folder) | ||
result = os.popen("git status --porcelain").read() | ||
if not os.path.exists(".git"): | ||
print("错误: 当前目录不是git仓库") | ||
exit(1) | ||
if result: | ||
print("错误: git仓库不干净,请先提交所有更改") | ||
print("未提交的更改:") | ||
print(result) | ||
exit(1) | ||
print("git仓库状态检查通过") |
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,14 @@ | ||
import shutil | ||
import tempfile | ||
|
||
|
||
class TempFolder: | ||
def __init__(self): | ||
self.folder = tempfile.mkdtemp() | ||
|
||
def __enter__(self): | ||
return self.folder | ||
|
||
def __exit__(self, exc_type, exc_value, traceback): | ||
# shutil.rmtree(self.folder) | ||
pass |
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,37 @@ | ||
import os | ||
import time | ||
|
||
import pytest | ||
|
||
from easybuilder.checker import check_clean | ||
from easybuilder.temputils import TempFolder | ||
|
||
|
||
@pytest.fixture | ||
def create_dirty_temp_repo(): | ||
with TempFolder() as tmp_folder: | ||
os.chdir(tmp_folder) | ||
os.system("git init") | ||
with open("README.md", "w") as f: | ||
f.write("test") | ||
|
||
# not clean | ||
yield tmp_folder | ||
|
||
|
||
@pytest.fixture | ||
def create_clean_temp_repo(): | ||
with TempFolder() as tmp_folder: | ||
os.chdir(tmp_folder) | ||
os.system("git init") | ||
yield tmp_folder | ||
|
||
|
||
def test_no_git(create_dirty_temp_repo): | ||
# we should create a new directory and check it | ||
with pytest.raises(SystemExit): | ||
check_clean(create_dirty_temp_repo) | ||
|
||
|
||
def test_clean(create_clean_temp_repo): | ||
check_clean(create_clean_temp_repo) |