blob: 45f837970a29e27194310f07f7567e8776ca7a05 [file] [log] [blame]
#!/usr/bin/env python3
import argparse
import sys
import os
# Allow importing of root-relative modules.
ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(os.path.join(ROOT_DIR))
#pylint: disable=wrong-import-position
from python.tools.git_utils import run_git_command, get_current_branch
#pylint: enable=wrong-import-position
def main():
parser = argparse.ArgumentParser(
description='Set parent branch config for target branch.')
parser.add_argument('parent_branch', help='Name of the parent branch')
parser.add_argument(
'-t',
'--target',
metavar='branch_name',
default=None,
help='Target branch (default: current)')
args = parser.parse_args()
target_branch = args.target or get_current_branch()
if not target_branch:
print("Error: Cannot determine target branch.", file=sys.stderr)
sys.exit(1)
parent_branch = args.parent_branch
run_git_command(['config', f'branch.{target_branch}.parent', parent_branch])
print(f"Set parent of '{target_branch}' to '{parent_branch}'.")
if __name__ == "__main__":
main()