|
| 1 | +import os |
| 2 | +from pdb import run |
| 3 | +import subprocess |
| 4 | + |
| 5 | + |
| 6 | +def run_command(command: str): |
| 7 | + |
| 8 | + try: |
| 9 | + result = subprocess.run( |
| 10 | + command, |
| 11 | + shell=True, |
| 12 | + check=True, |
| 13 | + text=True, |
| 14 | + capture_output=True |
| 15 | + ) |
| 16 | + print(result.stdout.strip()) |
| 17 | + except subprocess.CalledProcessError as e: |
| 18 | + print(f"Error: {e.stderr.strip()}") |
| 19 | + |
| 20 | + |
| 21 | +def set_working_directory(): |
| 22 | + |
| 23 | + path = input("Introduce el directorio completo de trabajo: ") |
| 24 | + if os.path.isdir(path): |
| 25 | + os.chdir(path) |
| 26 | + print(f"El directorio de trabajo ha cambiado a: {path}") |
| 27 | + else: |
| 28 | + print("El directorio introducido no existe.") |
| 29 | + |
| 30 | + |
| 31 | +def create_repository(): |
| 32 | + if os.path.isdir(".git"): |
| 33 | + print("Ya existe un repositorio en este directorio.") |
| 34 | + else: |
| 35 | + run_command("git init") |
| 36 | + run_command("git branch -M main") |
| 37 | + print("Repositorio inicializado.") |
| 38 | + |
| 39 | + |
| 40 | +def create_branch(): |
| 41 | + branch_name = input("Nombre de la nueva rama: ") |
| 42 | + run_command(f"git branch {branch_name}") |
| 43 | + |
| 44 | + |
| 45 | +def switch_branch(): |
| 46 | + branch_name = input("Nombre de la rama a la que quieres cambiar: ") |
| 47 | + run_command(f"git checkout {branch_name}") |
| 48 | + |
| 49 | + |
| 50 | +def show_pending_files(): |
| 51 | + run_command("git status -s") |
| 52 | + |
| 53 | + |
| 54 | +def make_commit(): |
| 55 | + message = input("Mensaje para el commit: ") |
| 56 | + run_command("git add .") |
| 57 | + run_command(f"git commit -m \"{message}\"") |
| 58 | + |
| 59 | + |
| 60 | +def show_commit_history(): |
| 61 | + run_command("git log --oneline") |
| 62 | + |
| 63 | + |
| 64 | +def delete_branch(): |
| 65 | + branch_name = input("Nombre de la rama a eliminar: ") |
| 66 | + run_command(f"git branch -d {branch_name}") |
| 67 | + |
| 68 | + |
| 69 | +def set_remote_repository(): |
| 70 | + remote_url = input("URL del repositorio remoto: ") |
| 71 | + run_command(f"git remote add origin {remote_url}") |
| 72 | + run_command("git push -u origin main") |
| 73 | + |
| 74 | + |
| 75 | +def make_pull(): |
| 76 | + run_command("git pull") |
| 77 | + |
| 78 | + |
| 79 | +def make_push(): |
| 80 | + run_command("git push") |
| 81 | + |
| 82 | + |
| 83 | +while True: |
| 84 | + |
| 85 | + print("\nDirectorio actual de trabajo:") |
| 86 | + run_command("pwd") |
| 87 | + |
| 88 | + print("\nGit y GitHub CLI - Opciones:") |
| 89 | + print("1. Establecer el directorio de trabajo") |
| 90 | + print("2. Crear un nuevo repositorio") |
| 91 | + print("3. Crear una nueva rama") |
| 92 | + print("4. Cambiar de rama") |
| 93 | + print("5. Mostrar ficheros pendientes de hacer commit") |
| 94 | + print("6. Hacer commit (+add)") |
| 95 | + print("7. Mostrar el historial de commits") |
| 96 | + print("8. Eliminar rama") |
| 97 | + print("9. Establecer repositorio remoto") |
| 98 | + print("10. Hacer pull") |
| 99 | + print("11. Hacer push") |
| 100 | + print("12. Salir") |
| 101 | + |
| 102 | + choice = input("Selecciona una opción (1 al 12): ") |
| 103 | + |
| 104 | + match choice: |
| 105 | + case "1": |
| 106 | + set_working_directory() |
| 107 | + case "2": |
| 108 | + create_repository() |
| 109 | + case "3": |
| 110 | + create_branch() |
| 111 | + case "4": |
| 112 | + switch_branch() |
| 113 | + case "5": |
| 114 | + show_pending_files() |
| 115 | + case "6": |
| 116 | + make_commit() |
| 117 | + case "7": |
| 118 | + show_commit_history() |
| 119 | + case "8": |
| 120 | + delete_branch() |
| 121 | + case "9": |
| 122 | + set_remote_repository() |
| 123 | + case "10": |
| 124 | + make_pull() |
| 125 | + case "11": |
| 126 | + make_push() |
| 127 | + case "12": |
| 128 | + print("Saliendo...") |
| 129 | + break |
| 130 | + case _: |
| 131 | + print("Opción no válida.") |
0 commit comments