| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 75e6c6b commit b0354d5
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -242,6 +242,20 @@ def __init__( | |||
| 242 | 242 | # It's important to normalize the paths, as submodules will otherwise | |
| 243 | 243 | # initialize their repo instances with paths that depend on path-portions | |
| 244 | 244 | # that will not exist after being removed. It's just cleaner. | |
| 245 | + if ( | ||
| 246 | + osp.isfile(osp.join(curpath, "gitdir")) | ||
| 247 | + and osp.isfile(osp.join(curpath, "commondir")) | ||
| 248 | + and osp.isfile(osp.join(curpath, "HEAD")) | ||
| 249 | + ): | ||
| 250 | + git_dir = curpath | ||
| 251 | + worktree_gitfile = Path(osp.join(git_dir, "gitdir")).read_text().splitlines()[0].strip() | ||
| 252 | + if not osp.isabs(worktree_gitfile): | ||
| 253 | + worktree_gitfile = osp.normpath(osp.join(git_dir, worktree_gitfile)) | ||
| 254 | + self._working_tree_dir = osp.dirname(worktree_gitfile) | ||
| 255 | + if "GIT_WORK_TREE" in os.environ: | ||
| 256 | + self._working_tree_dir = os.getenv("GIT_WORK_TREE") | ||
| 257 | + break | ||
| 258 | + | ||
| 245 | 259 | if is_git_dir(curpath): | |
| 246 | 260 | git_dir = curpath | |
| 247 | 261 | # from man git-config : core.worktree | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1126,6 +1126,37 @@ def test_git_work_tree_env(self, rw_dir): | |||
| 1126 | 1126 | self.assertEqual(r.working_tree_dir, repo_dir) | |
| 1127 | 1127 | self.assertEqual(r.working_dir, repo_dir) | |
| 1128 | 1128 | ||
| 1129 | + @with_rw_directory | ||
| 1130 | + def test_git_work_tree_env_in_linked_worktree(self, rw_dir): | ||
| 1131 | + """Check that Repo() autodiscovers a linked worktree when GIT_DIR is set.""" | ||
| 1132 | + git = Git(rw_dir) | ||
| 1133 | + if git.version_info[:3] < (2, 5, 1): | ||
| 1134 | + raise RuntimeError("worktree feature unsupported (test needs git 2.5.1 or later)") | ||
| 1135 | + | ||
| 1136 | + rw_master = self.rorepo.clone(join_path_native(rw_dir, "master_repo")) | ||
| 1137 | + branch = rw_master.create_head("bbbbbbbb") | ||
| 1138 | + worktree_path = join_path_native(rw_dir, "worktree_repo") | ||
| 1139 | + if Git.is_cygwin(): | ||
| 1140 | + worktree_path = cygpath(worktree_path) | ||
| 1141 | + | ||
| 1142 | + rw_master.git.worktree("add", worktree_path, branch.name) | ||
| 1143 | + | ||
| 1144 | + git_dir = Git(worktree_path).rev_parse("--git-dir") | ||
| 1145 | + | ||
| 1146 | + with mock.patch.dict(os.environ, {"GIT_DIR": git_dir}, clear=False): | ||
| 1147 | + old_cwd = os.getcwd() | ||
| 1148 | + try: | ||
| 1149 | + os.chdir(worktree_path) | ||
| 1150 | + | ||
| 1151 | + explicit = Repo(os.getcwd()) | ||
| 1152 | + autodiscovered = Repo() | ||
| 1153 | + | ||
| 1154 | + self.assertTrue(osp.samefile(explicit.working_tree_dir, worktree_path)) | ||
| 1155 | + self.assertTrue(osp.samefile(autodiscovered.working_tree_dir, worktree_path)) | ||
| 1156 | + self.assertTrue(osp.samefile(autodiscovered.working_tree_dir, explicit.working_tree_dir)) | ||
| 1157 | + finally: | ||
| 1158 | + os.chdir(old_cwd) | ||
| 1159 | + | ||
| 1129 | 1160 | @with_rw_directory | |
| 1130 | 1161 | def test_rebasing(self, rw_dir): | |
| 1131 | 1162 | r = Repo.init(rw_dir) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments