From caf47b55965ef7ca7f3fed4b88efd501c91dc4bc Mon Sep 17 00:00:00 2001 From: Jhon Pedroza Date: Sat, 24 Sep 2022 23:18:25 -0500 Subject: [PATCH] fix(git): Fix update_repo when there are untracked files --- libvcs/projects/git.py | 4 ++-- tests/projects/test_git.py | 27 ++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/libvcs/projects/git.py b/libvcs/projects/git.py index 775ed3f8..98d593c7 100644 --- a/libvcs/projects/git.py +++ b/libvcs/projects/git.py @@ -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") diff --git a/tests/projects/test_git.py b/tests/projects/test_git.py index ed8b95eb..4109c5d0 100644 --- a/tests/projects/test_git.py +++ b/tests/projects/test_git.py @@ -108,7 +108,7 @@ 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, @@ -116,6 +116,15 @@ def test_repo_git_obtain_full( "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, @@ -123,6 +132,15 @@ def test_repo_git_obtain_full( "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 ], ], ) @@ -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()