Skip to content
Open
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
6 changes: 4 additions & 2 deletions hooks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ def get_untracked_files() -> List[str]:


def get_current_branch() -> str:
output = subprocess.check_output(BRANCH_CMD)
return output.decode().rstrip()
result = subprocess.run(BRANCH_CMD, stdout=subprocess.PIPE)
if result.returncode == 0:
return result.stdout.decode().rstrip()
return None
10 changes: 10 additions & 0 deletions tests/check_untracked_migrations_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,13 @@ def test_running_on_correct_branch(temp_git_dir):
def test_running_on_incorrect_branch(temp_git_dir):
with temp_git_dir.as_cwd():
assert main(["--branches", "branch_one", "branch_two"]) == 1


def test_running_on_detached_head_no_filter(temp_git_detached_dir):
with temp_git_detached_dir.as_cwd():
assert main() == 0


def test_running_on_detached_head_with_filter(temp_git_detached_dir):
with temp_git_detached_dir.as_cwd():
assert main(["--branches", "branch_one", "branch_two"]) == 1
11 changes: 11 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,14 @@ def temp_git_dir(tmpdir):
git_dir = tmpdir.join("gits")
subprocess.call(["git", "init", "--", str(git_dir)])
yield git_dir


@pytest.fixture
def temp_git_detached_dir(tmpdir):
git_dir = tmpdir.join("gits")
subprocess.call(["git", "init", "--", str(git_dir)])
subprocess.call(
["git", "commit", "--allow-empty", "-m", "initial commit"], cwd=git_dir
)
subprocess.call(["git", "checkout", "--detach"], cwd=git_dir)
yield git_dir