| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -49,6 +49,7 @@ | |||
| 49 | 49 | Callable, | |
| 50 | 50 | Dict, | |
| 51 | 51 | Iterator, | |
| 52 | + List, | ||
| 52 | 53 | Mapping, | |
| 53 | 54 | Sequence, | |
| 54 | 55 | TYPE_CHECKING, | |
@@ -1267,6 +1268,36 @@ def remove( | |||
| 1267 | 1268 | ||
| 1268 | 1269 | return self | |
| 1269 | 1270 | ||
| 1271 | + @unbare_repo | ||
| 1272 | + def deinit(self, force: bool = False) -> "Submodule": | ||
| 1273 | + """Run ``git submodule deinit`` on this submodule. | ||
| 1274 | + | ||
| 1275 | + This is a thin wrapper around ``git submodule deinit <path>``, | ||
| 1276 | + which unregisters the submodule (removes its entry from | ||
| 1277 | + ``.git/config`` and empties the working-tree directory) | ||
| 1278 | + without deleting the submodule from ``.gitmodules`` | ||
| 1279 | + or its checked-out repository under ``.git/modules/``. | ||
| 1280 | + A subsequent :meth:`update` will re-initialize the | ||
| 1281 | + submodule from the retained contents. | ||
| 1282 | + | ||
| 1283 | + :param force: | ||
| 1284 | + If ``True``, pass ``--force`` to ``git submodule deinit``. This | ||
| 1285 | + allows deinitialization even when the submodule's working tree has | ||
| 1286 | + local modifications that would otherwise block the command. | ||
| 1287 | + | ||
| 1288 | + :return: | ||
| 1289 | + self | ||
| 1290 | + | ||
| 1291 | + :note: | ||
| 1292 | + Doesn't work in bare repositories. | ||
| 1293 | + """ | ||
| 1294 | + args: List[str] = [] | ||
| 1295 | + if force: | ||
| 1296 | + args.append("--force") | ||
| 1297 | + args.extend(["--", str(self.path)]) | ||
| 1298 | + self.repo.git.submodule("deinit", *args) | ||
| 1299 | + return self | ||
| 1300 | + | ||
| 1270 | 1301 | def set_parent_commit(self, commit: Union[Commit_ish, str, None], check: bool = True) -> "Submodule": | |
| 1271 | 1302 | """Set this instance to use the given commit whose tree is supposed to | |
| 1272 | 1303 | contain the ``.gitmodules`` blob. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -713,6 +713,21 @@ def test_iter_items_from_invalid_hash(self): | |||
| 713 | 713 | next(it) | |
| 714 | 714 | self.assertIsNone(ctx.exception.value) | |
| 715 | 715 | ||
| 716 | + @with_rw_directory | ||
| 717 | + def test_deinit_calls_git_submodule(self, rwdir): | ||
| 718 | + repo = git.Repo.init(rwdir) | ||
| 719 | + submodule = Submodule(repo, b"\0" * 20, name="module", path="module") | ||
| 720 | + | ||
| 721 | + with mock.patch.object(Git, "submodule", create=True) as git_submodule: | ||
| 722 | + submodule.deinit() | ||
| 723 | + | ||
| 724 | + git_submodule.assert_called_once_with("deinit", "--", submodule.path) | ||
| 725 | + git_submodule.reset_mock() | ||
| 726 | + | ||
| 727 | + submodule.deinit(force=True) | ||
| 728 | + | ||
| 729 | + git_submodule.assert_called_once_with("deinit", "--force", "--", submodule.path) | ||
| 730 | + | ||
| 716 | 731 | @with_rw_repo(k_no_subm_tag, bare=False) | |
| 717 | 732 | def test_first_submodule(self, rwrepo): | |
| 718 | 733 | assert len(list(rwrepo.iter_submodules())) == 0 | |
| Back | FazBrowse Home | New Git URL |
0 commit comments