Skip to content

Commit

Permalink
fix(git): Fix update_repo when there are untracked files
Browse files Browse the repository at this point in the history
  • Loading branch information
jfpedroza committed Sep 25, 2022
1 parent ff9247b commit caf47b5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
4 changes: 2 additions & 2 deletions libvcs/projects/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,9 @@ def update_repo(self, set_remotes: bool = False, *args, **kwargs):
# to be able to perform git pull --rebase
if need_stash:
# If Git < 1.7.6, uses --quiet --all
git_stash_save_options = "--quiet"
git_stash_save_options = ["--quiet", "--include-untracked"]
try:
process = self.run(["stash", "save", git_stash_save_options])
process = self.run(["stash", "save"] + git_stash_save_options)
except exc.CommandError:
self.log.error("Failed to stash changes")

Expand Down
27 changes: 26 additions & 1 deletion tests/projects/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,39 @@ def test_repo_git_obtain_full(

@pytest.mark.parametrize(
# Postpone evaluation of options so fixture variables can interpolate
"constructor,lazy_constructor_options",
"constructor,lazy_constructor_options,has_untracked_files",
[
[
GitProject,
lambda git_remote_repo, tmp_path, **kwargs: {
"url": f"file://{git_remote_repo}",
"dir": tmp_path / "myrepo",
},
False
],
[
GitProject,
lambda git_remote_repo, tmp_path, **kwargs: {
"url": f"file://{git_remote_repo}",
"dir": tmp_path / "myrepo",
},
True
],
[
create_project_from_pip_url,
lambda git_remote_repo, tmp_path, **kwargs: {
"pip_url": f"git+file://{git_remote_repo}",
"dir": tmp_path / "myrepo",
},
False
],
[
create_project_from_pip_url,
lambda git_remote_repo, tmp_path, **kwargs: {
"pip_url": f"git+file://{git_remote_repo}",
"dir": tmp_path / "myrepo",
},
True
],
],
)
Expand All @@ -132,9 +150,16 @@ def test_repo_update_handle_cases(
mocker: MockerFixture,
constructor: ProjectTestFactory,
lazy_constructor_options: ProjectTestFactoryLazyKwargs,
has_untracked_files: bool,
):
git_repo: GitProject = constructor(**lazy_constructor_options(**locals()))
git_repo.obtain() # clone initial repo

if has_untracked_files:
some_file = git_repo.dir.joinpath("some_file")
with open(some_file, "w") as untracked_file:
untracked_file.write("some content")

mocka = mocker.spy(git_repo, "run")
git_repo.update_repo()

Expand Down

0 comments on commit caf47b5

Please sign in to comment.