diff --git a/README.md b/README.md index d9ae761..1543529 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,7 @@ configured branch, use `./git-external clone`. url = "${ibrvsscloud}/foo" path = "foo" vcs = none -- `script = none`: Execute a script after cloning the external +- `script = none`: Execute a script located at repository root after cloning the external. Note: not supported on Windows (including git-bash). [external "foo"] script = run.sh @@ -109,6 +109,13 @@ configured branch, use `./git-external clone`. ... updateArgs = --sparse +- `sparseCheckout`: Enable and configure sparse checkout. If this option is not present or is empty, sparse checkout is disabled. Note, `--sparse` option to `cloneArgs` or `updateArgs` is not required for this to work. + + [external "foo"] + ... + sparseCheckout = "bar baz" + + ## Overrides You can overide the settings for externals by putting an external diff --git a/bin/git-external b/bin/git-external index 631173b..61146f9 100755 --- a/bin/git-external +++ b/bin/git-external @@ -304,6 +304,20 @@ class GitExternal: ret = cur_branch.stdout.decode().strip() return ret or None + def update_sparse_checkout(self, repo, path, config): + """Updates the current set of sparse checkouts""" + sparse_checkout = get_args(config, "sparseCheckout") + cur_dir = os.curdir + os.chdir(path) + if sparse_checkout: + log.info(f"[{repo}] Setting sparse-checkout to {sparse_checkout}") + cmd = ["git", "sparse-checkout", "set"] + sparse_checkout + else: + log.info(f"[{repo}] Sparse checkout not in use, disabled") + cmd = ["git", "sparse-checkout", "disable"] + check_call(cmd) + os.chdir(cur_dir) + def init_or_update(self, recursive=True, only=None, external=None): """Init or update all repositories in self.configurations. @@ -355,6 +369,7 @@ class GitExternal: opts = get_args(config, "updateArgs") log.info(f"[{repo}] Updating Git external, {opts}") check_call(["git", "pull", "--ff-only"] + opts, cwd=path) + self.update_sparse_checkout(repo, path, config) elif cur_branch is None: log.warning(f"[{repo}] Skipping update, detached HEAD") else: @@ -407,7 +422,7 @@ class GitExternal: cmd = ["git", "clone"] + opts + [config["url"], path] print(" ".join(cmd)) check_call(cmd) - + self.update_sparse_checkout(repo, path, config) cur_branch = self.get_branch_name(path) branch = config.get('branch') or "master" if cur_branch != branch: diff --git a/setup.py b/setup.py index e94e212..9f1adab 100755 --- a/setup.py +++ b/setup.py @@ -18,6 +18,6 @@ ], zip_safe=False, scripts=['bin/git-external'], - python_requires='>=3.6' + python_requires='>=3.7' )