Skip to content

Commit b444275

Browse files
committed
fix(git): Fix update_repo when there are untracked files
1 parent 1a14726 commit b444275

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

src/libvcs/sync/git.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,9 +418,9 @@ def update_repo(self, set_remotes: bool = False, *args: Any, **kwargs: Any) -> N
418418
# to be able to perform git pull --rebase
419419
if need_stash:
420420
# If Git < 1.7.6, uses --quiet --all
421-
git_stash_save_options = "--quiet"
421+
git_stash_save_options = ["--quiet", "--include-untracked"]
422422
try:
423-
process = self.run(["stash", "save", git_stash_save_options])
423+
process = self.run(["stash", "save"] + git_stash_save_options)
424424
except exc.CommandError:
425425
self.log.error("Failed to stash changes")
426426

tests/sync/test_git.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def test_repo_git_obtain_full(
112112

113113
@pytest.mark.parametrize(
114114
# Postpone evaluation of options so fixture variables can interpolate
115-
"constructor,lazy_constructor_options",
115+
"constructor,lazy_constructor_options,has_untracked_files",
116116
[
117117
[
118118
GitSync,
@@ -121,6 +121,16 @@ def test_repo_git_obtain_full(
121121
"dir": tmp_path / "myrepo",
122122
"vcs": "git",
123123
},
124+
False,
125+
],
126+
[
127+
GitSync,
128+
lambda git_remote_repo, tmp_path, **kwargs: {
129+
"url": f"file://{git_remote_repo}",
130+
"dir": tmp_path / "myrepo",
131+
"vcs": "git",
132+
},
133+
True,
124134
],
125135
[
126136
create_project,
@@ -129,6 +139,16 @@ def test_repo_git_obtain_full(
129139
"dir": tmp_path / "myrepo",
130140
"vcs": "git",
131141
},
142+
False,
143+
],
144+
[
145+
create_project,
146+
lambda git_remote_repo, tmp_path, **kwargs: {
147+
"url": f"git+file://{git_remote_repo}",
148+
"dir": tmp_path / "myrepo",
149+
"vcs": "git",
150+
},
151+
True,
132152
],
133153
],
134154
)
@@ -138,9 +158,16 @@ def test_repo_update_handle_cases(
138158
mocker: MockerFixture,
139159
constructor: ProjectTestFactory,
140160
lazy_constructor_options: ProjectTestFactoryLazyKwargs,
161+
has_untracked_files: bool,
141162
) -> None:
142163
git_repo: GitSync = constructor(**lazy_constructor_options(**locals()))
143164
git_repo.obtain() # clone initial repo
165+
166+
if has_untracked_files:
167+
some_file = git_repo.dir.joinpath("some_file")
168+
with open(some_file, "w") as untracked_file:
169+
untracked_file.write("some content")
170+
144171
mocka = mocker.spy(git_repo, "run")
145172
git_repo.update_repo()
146173

0 commit comments

Comments
 (0)