Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checkout_pull_branch() fails when existing checked-out branch has local changes #246

Closed
colinodell opened this issue Jul 27, 2022 · 0 comments · Fixed by #249
Closed

checkout_pull_branch() fails when existing checked-out branch has local changes #246

colinodell opened this issue Jul 27, 2022 · 0 comments · Fixed by #249

Comments

@colinodell
Copy link
Collaborator

colinodell commented Jul 27, 2022

checkout_pull_branch() to perform a pull, but this doesn't work when the local copy has untracked changes:

Traceback (most recent call last):
  File "/pyenv/versions/[redacted]/lib/python3.9/site-packages/pygitops/operations.py", line 193, in get_updated_repo
    _checkout_pull_branch(repo, branch)
  File "/pyenv/versions/[redacted]/lib/python3.9/site-packages/pygitops/_util.py", line 82, in checkout_pull_branch
    origin.pull(branch)
  File "/pyenv/versions/[redacted]/lib/python3.9/site-packages/git/remote.py", line 910, in pull
    res = self._get_fetch_info_from_stderr(proc, progress,
  File "/pyenv/versions/[redacted]/lib/python3.9/site-packages/git/remote.py", line 750, in _get_fetch_info_from_stderr
    proc.wait(stderr=stderr_text)
  File "/pyenv/versions/[redacted]/lib/python3.9/site-packages/git/cmd.py", line 502, in wait
    raise GitCommandError(remove_password_if_present(self.args), status, errstr)
git.exc.GitCommandError: Cmd('git') failed due to: exit code(1)
  cmdline: git pull -v origin main
  stderr: 'error: Your local changes to the following files would be overwritten by merge:'

Suggested Fix

We could allow an optional force arg to be provided. If set and True, we would pass this option to the git checkout command to discard any changes to the index and working tree. An additional git clean command could also be run to remove untracked files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant