diff --git a/llvm/utils/git-llvm-push b/llvm/utils/git-llvm-push index 84a84aa52335a..538dd893990b4 100755 --- a/llvm/utils/git-llvm-push +++ b/llvm/utils/git-llvm-push @@ -28,6 +28,8 @@ LLVM_GITHUB_TOKEN_VAR = "LLVM_GITHUB_TOKEN" LLVM_REPO = "llvm/llvm-project" GITHUB_API = "https://api.github.com" +GIT_CONFIG_PREFIX = "git-llvm-push." + MERGE_MAX_RETRIES = 10 MERGE_RETRY_DELAY = 5 # seconds REQUEST_TIMEOUT = 30 # seconds @@ -604,6 +606,27 @@ def get_token_from_cli(runner: CommandRunner) -> str: return result.stdout.strip().decode("utf-8") +def get_git_config_options() -> argparse.Namespace: + # We do not use a runner here as we need to run this before we know what + # flags we want to pass to the runner. + try: + process = subprocess.run( + ["git", "config", "--list"], stdout=subprocess.PIPE, stderr=subprocess.PIPE + ) + args = argparse.Namespace() + for line in process.stdout.decode("utf-8").split("\n"): + if line.startswith(GIT_CONFIG_PREFIX): + line_parts = line.split("=") + setattr( + args, + line_parts[0][len(GIT_CONFIG_PREFIX) :].replace("-", "_"), + line_parts[1], + ) + return args + except: + return argparse.Namespace() + + def main() -> None: parser = argparse.ArgumentParser( description="Create and land a stack of Pull Requests." @@ -671,7 +694,8 @@ def main() -> None: help="Print only essential output and errors.", ) - args = parser.parse_args() + git_config_args = get_git_config_options() + args = parser.parse_args(None, git_config_args) command_runner = CommandRunner( dry_run=args.dry_run, verbose=args.verbose, quiet=args.quiet diff --git a/llvm/utils/git-llvm-push.md b/llvm/utils/git-llvm-push.md index a8fa31b4b44db..3b1ece1d05587 100644 --- a/llvm/utils/git-llvm-push.md +++ b/llvm/utils/git-llvm-push.md @@ -54,6 +54,22 @@ Regardless of success or failure, the script performs the following cleanup step 1. **Checkout Original Branch:** The script will check out the branch you were on when you started the script. 2. **Delete Temporary Remote Branches:** Any temporary branches created on your fork (e.g., `users/johndoe/my-feature-1`) will be deleted from the remote. This prevents clutter in your fork. +## Configuration + +In addition to accepting command line flags, `git-llvm-push` can also be configured +through the git config. To do this, edit your git config (using a command like +`git config --edit` to edit your repo specific configuration) and add the following +section header: + +``` +[git-llvm-push] + = +``` + +The flags are spelled the exact same as they are on the command line. All flags +are supported, although `--verbose` and `--dry-run` will not have an impact on +the git invocation to read the configuration. + ## Examples ### Dry Run (Safe Mode)