diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index d31eff919..f2f044e40 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,5 +1,9 @@ # Release notes +## New in git-machete 3.6.1 + +- fixed: support for worktrees (reported by @kgadek) + ## New in git-machete 3.6.0 - added: `t` alias for `traverse` command diff --git a/docs/source/cli_help/discover.rst b/docs/source/cli_help/discover.rst index 79cec4f2a..a5ba76873 100644 --- a/docs/source/cli_help/discover.rst +++ b/docs/source/cli_help/discover.rst @@ -9,7 +9,7 @@ discover git machete discover [-C|--checked-out-since=] [-l|--list-commits] [-r|--roots=,,...] [-y|--yes] Discovers and displays tree of branch dependencies using a heuristic based on reflogs and asks whether to overwrite the existing definition :ref:`file` with the new discovered tree. -If confirmed with a ``y[es]`` or ``e[dit]`` reply, backs up the current definition file (if it exists) as ``$GIT_DIR/machete~`` and saves the new tree under the usual ``$GIT_DIR/machete`` path. +If confirmed with a ``y[es]`` or ``e[dit]`` reply, backs up the current definition file (if it exists) as ``machete~`` and saves the new tree in the usual ``machete`` file. If the reply was ``e[dit]``, additionally an editor is opened (as in :ref:`git machete edit`) after saving the new definition file. **Options:** diff --git a/docs/source/cli_help/file.rst b/docs/source/cli_help/file.rst index 06dad9c1e..2fc7937c5 100644 --- a/docs/source/cli_help/file.rst +++ b/docs/source/cli_help/file.rst @@ -10,3 +10,11 @@ file Outputs the absolute path of the machete definition file. Currently fixed to ``/machete``. Note: this won't always be just ``/.git/machete`` since e.g. submodules and worktrees have their git directories in different location. + +Outputs the absolute path of the machete definition file. +The file is always called ``machete`` and is located in the git directory of the project. + +Three cases are possible: + * if ``git machete`` is executed from a regular working directory (not a worktree or submodule), this simply resolves to `machete` in .git folder, + * if `git machete` is executed from a **worktree**, this resolves to `machete` in the .git folder of the **top-level project** (not the worktree's .git folder!), + * if `git machete` is executed from a **submodule**, this resolves to `machete` in the .git folder of the **submodule** itself (not the top-level project's .git folder!). diff --git a/docs/source/completion.rst b/docs/source/completion.rst index 2c01e6ac6..68108a9cf 100644 --- a/docs/source/completion.rst +++ b/docs/source/completion.rst @@ -101,7 +101,7 @@ Fish: Please look at the section about [installation via Homebrew](https://github.com/VirtusLab/git-machete#using-homebrew-macos). ``brew install git-machete`` automatically installs fish completion files for ``git machete``. * Linux - #. Place the completion script in ``/path/to/fish/completions/`` (typically ``~/.config/fish/completions/git-machete.fish``). + Place the completion script in ``/path/to/fish/completions/`` (typically ``~/.config/fish/completions/git-machete.fish``). .. code-block:: shell diff --git a/git_machete/__init__.py b/git_machete/__init__.py index 826cf62ca..bce598245 100644 --- a/git_machete/__init__.py +++ b/git_machete/__init__.py @@ -1 +1 @@ -__version__ = '3.6.0' +__version__ = '3.6.1' diff --git a/git_machete/docs.py b/git_machete/docs.py index 803bb3dc6..1d94a4775 100644 --- a/git_machete/docs.py +++ b/git_machete/docs.py @@ -168,7 +168,7 @@ Usage: git machete discover [-C|--checked-out-since=] [-l|--list-commits] [-r|--roots=,,...] [-y|--yes] Discovers and displays tree of branch dependencies using a heuristic based on reflogs and asks whether to overwrite the existing definition file with the new discovered tree. - If confirmed with a `y[es]` or `e[dit]` reply, backs up the current definition file (if it exists) as `$GIT_DIR/machete~` and saves the new tree under the usual `$GIT_DIR/machete` path. + If confirmed with a `y[es]` or `e[dit]` reply, backs up the current definition file (if it exists) as `machete~` and saves the new tree in the usual `machete` file. If the reply was `e[dit]`, additionally an editor is opened (as in `git machete edit`) after saving the new definition file. Options: @@ -208,8 +208,13 @@ "file": """ Usage: git machete file - Outputs the absolute path of the machete definition file. Currently fixed to `/machete`. - Note: this won't always be just `/.git/machete` since e.g. submodules and worktrees have their git directories in different location. + Outputs the absolute path of the machete definition file. + The file is always called `machete` and is located in the git directory of the project. + + Three cases are possible: + * if `git machete` is executed from a regular working directory (not a worktree or submodule), this simply resolves to `machete` in .git folder, + * if `git machete` is executed from a worktree, this resolves to `machete` in the .git folder of the top-level project (not the worktree's .git folder!), + * if `git machete` is executed from a submodule, this resolves to `machete` in the .git folder of the submodule itself (not the top-level project's .git folder!). """, "fork-point": """ Usage: diff --git a/git_machete/git_operations.py b/git_machete/git_operations.py index d060205db..85a740d3a 100644 --- a/git_machete/git_operations.py +++ b/git_machete/git_operations.py @@ -1,3 +1,4 @@ +from pathlib import Path from typing import Callable, Dict, Generator, Iterator, List, Match, Optional, Set, Tuple import os @@ -255,7 +256,14 @@ def get_root_dir(self) -> str: def __get_git_dir(self) -> str: if not self._git_dir: try: - self._git_dir = self._popen_git("rev-parse", "--git-dir").strip() + git_dir: str = self._popen_git("rev-parse", "--git-dir").strip() + git_dir_parts = Path(git_dir).parts + if len(git_dir_parts) >= 3 and git_dir_parts[-3] == '.git' and git_dir_parts[-2] == 'worktrees': + self._git_dir = os.path.join(*git_dir_parts[:-2]) + debug('__get_git_dir', f'git dir pointing to {git_dir} - we are in a worktree; ' + f'using {self._git_dir} as the effective git dir instead') + else: + self._git_dir = git_dir except MacheteException: raise MacheteException("Not a git repository") return self._git_dir diff --git a/git_machete/tests/functional/test_machete.py b/git_machete/tests/functional/test_machete.py index 53cef1e6d..03bbdc60f 100644 --- a/git_machete/tests/functional/test_machete.py +++ b/git_machete/tests/functional/test_machete.py @@ -456,14 +456,15 @@ def setup_discover_standard_tree(self) -> None: ) @mock.patch('git_machete.utils.run_cmd', mock_run_cmd) # to hide git outputs in tests - def test_branch_reappers_in_definition(self) -> None: + def test_branch_reappears_in_definition(self) -> None: body: str = \ """master \tdevelop \t\n develop """ - expected_error_msg: str = fmt('.git/machete, line 5: branch `develop` re-appears in the tree definition. Edit the definition file manually with `git machete edit`') + expected_error_msg: str = fmt('.git/machete, line 5: branch `develop` re-appears in the tree definition. ' + 'Edit the definition file manually with `git machete edit`') self.repo_sandbox.new_branch("root") self.rewrite_definition_file(body) diff --git a/tox.ini b/tox.ini index 74f388a87..16b836151 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = pep8,mypy-py{36,37,38,39},py{36,37,38,39},coverage,docs +envlist = pep8,mypy-py{36,37,38,39,310},py{36,37,38,39,310},coverage,docs minversion = 2.3.2 skipsdist = True @@ -32,7 +32,7 @@ exclude = ./.*,build,dist,*egg,venv import-order-style = pep8 [testenv:coverage] -description = "Checking the test coverage of the code." +description = "Check the test coverage of the code" deps = coverage commands = coverage erase @@ -51,9 +51,9 @@ commands = [testenv:mypy] whitelist_externals = tox -commands = tox -e "mypy-py{36,37,38,39}" +commands = tox -e "mypy-py{36,37,38,39,310}" -[testenv:mypy-py{36,37,38,39}] +[testenv:mypy-py{36,37,38,39,310}] deps = mypy commands = mypy --config-file mypy.ini git_machete