diff --git a/mobius_repos.py b/mobius_repos.py index c75cbe6..1c58e83 100755 --- a/mobius_repos.py +++ b/mobius_repos.py @@ -22,7 +22,7 @@ def print_colored(message, color, bold=False): def create_new_branch(repo_path, branch_name): """ - Create a new branch in the repository + Create a new branch from 'develop' branch in the repository """ try: os.chdir(repo_path) @@ -35,14 +35,26 @@ def create_new_branch(repo_path, branch_name): current_branch = subprocess.check_output(['git', 'branch', '--show-current']).decode().strip() print_colored(f"Current branch: {current_branch}", Colors.BLUE) - print_colored("Pulling latest changes...", Colors.BLUE) + # Check if develop branch exists + branches = subprocess.check_output(['git', 'branch', '-a']).decode() + if 'develop' not in branches and 'origin/develop' not in branches: + print_colored("The 'develop' branch does not exist!", Colors.RED) + return False + + # First checkout develop branch + subprocess.run(['git', 'checkout', 'develop'], check=True) + print_colored("Switched to the 'develop' branch", Colors.GREEN) + + # Pull latest changes from develop + print_colored("Pulling latest changes from develop...", Colors.BLUE) subprocess.run(['git', 'pull'], check=True) - branches = subprocess.check_output(['git', 'branch', '-a']).decode() + # Check if the new branch already exists if branch_name in branches: print_colored(f"Branch '{branch_name}' already exists!", Colors.YELLOW) return False + # Create new branch from develop subprocess.run(['git', 'checkout', '-b', branch_name], check=True) print_colored(f"Successfully created and switched to branch: {branch_name}", Colors.GREEN) @@ -124,18 +136,18 @@ or creating new branches across all repositories. epilog=''' Examples: python3 mob_repos.py # Switch to develop and pull in all repos - python3 mob_repos.py -bc feature/GND1111-testing-repo # Create new branch in all repos + python3 mob_repos.py -bc feature/GND1111-testing-repo # Create new branch from develop in all repos python3 mob_repos.py --help # Show this help message ''', formatter_class=argparse.RawDescriptionHelpFormatter ) - + parser.add_argument( '-bc', '--branch-create', - help='Create a new branch in all repositories (e.g., feature/GND1111-testing-repo)', + help='Create a new branch from develop in all repositories (e.g., feature/GND1111-testing-repo)', metavar='BRANCH_NAME' ) - + parser.add_argument( '-c', '--config', help='Path to configuration file (default: repos.txt)',