|
25 | 25 | logger: logging.Logger = logging.getLogger(__name__)
|
26 | 26 |
|
27 | 27 |
|
28 |
| -def reset_git_repo(git_obj: Git, stash: bool = True, index: bool = True, working_tree: bool = True) -> bool: |
29 |
| - """Reset the index and working tree of the target repository. |
30 |
| -
|
31 |
| - Note that this method does not reset any untracked or ignored files. |
32 |
| -
|
33 |
| - Parameters |
34 |
| - ---------- |
35 |
| - git_obj : Git |
36 |
| - The pydriller.Git object of the repository. |
37 |
| - stash : bool |
38 |
| - If True, any uncommitted changes will be stashed. |
39 |
| - index : bool |
40 |
| - If True, the index of the repository will be reset. |
41 |
| - working_tree : bool |
42 |
| - If True, the working tree will be forcefully adjusted to match HEAD, possibly overwriting uncommitted changes. |
43 |
| - If working_tree is True, index must be true as well. |
44 |
| -
|
45 |
| - Returns |
46 |
| - ------- |
47 |
| - bool |
48 |
| - True if no errors encountered, else False. |
49 |
| - """ |
50 |
| - try: |
51 |
| - if stash: |
52 |
| - logger.info("Stashing any uncommitted changes.") |
53 |
| - stash_out = git_obj.repo.git.stash(message="Stashing uncommitted changes by Macaron.") |
54 |
| - logger.debug("\t Git CMD output: %s", stash_out) |
55 |
| - |
56 |
| - logger.info("Forcefully reset the repository.") |
57 |
| - git_obj.repo.head.reset(index=index, working_tree=working_tree) |
58 |
| - return True |
59 |
| - except GitCommandError as error: |
60 |
| - logger.error("Error while trying to reset untracked changes in the repository: %s", error) |
61 |
| - return False |
62 |
| - except ValueError as error: |
63 |
| - logger.error(error) |
64 |
| - return False |
65 |
| - |
66 |
| - |
67 | 28 | def check_out_repo_target(git_obj: Git, branch_name: str = "", digest: str = "", offline_mode: bool = False) -> bool:
|
68 | 29 | """Checkout the branch and commit specified by the user.
|
69 | 30 |
|
@@ -123,7 +84,8 @@ def check_out_repo_target(git_obj: Git, branch_name: str = "", digest: str = "",
|
123 | 84 |
|
124 | 85 | try:
|
125 | 86 | # Switch to the target branch by running ``git checkout <branch_name>`` in the target repository.
|
126 |
| - git_obj.repo.git.checkout(res_branch) |
| 87 | + # We need to use force checkout to prevent issues similar to https://github.com/oracle/macaron/issues/530. |
| 88 | + git_obj.repo.git.checkout("--force", res_branch) |
127 | 89 | except GitCommandError as error:
|
128 | 90 | logger.error("Cannot checkout branch %s. Error: %s", res_branch, error)
|
129 | 91 | return False
|
@@ -153,8 +115,9 @@ def check_out_repo_target(git_obj: Git, branch_name: str = "", digest: str = "",
|
153 | 115 |
|
154 | 116 | if digest:
|
155 | 117 | # Checkout the specific commit that the user want by running ``git checkout <commit>`` in the target repository.
|
| 118 | + # We need to use force checkout to prevent issues similar to https://github.com/oracle/macaron/issues/530. |
156 | 119 | try:
|
157 |
| - git_obj.repo.git.checkout(digest) |
| 120 | + git_obj.repo.git.checkout("--force", digest) |
158 | 121 | except GitCommandError as error:
|
159 | 122 | logger.error(
|
160 | 123 | "Commit %s cannot be checked out. Error: %s",
|
|
0 commit comments