0

I wish to write a python script that allows me to navigate and git pull multiple repositories. Basically the script should type the following on the command-line:

cd
cd ~/Desktop/Git_Repo
git pull Git_Repo

I am not sure if there is a python library already out there that can perform such a task.

Jack_The_Ripper
  • 603
  • 2
  • 6
  • 23
  • 1
    http://stackoverflow.com/questions/89228/calling-an-external-command-in-python – muthan Nov 11 '14 at 03:52
  • 1
    I don't know what other functionality you intend to add but can't you just do this as a shell one liner? `for i in *; do (cd $i && git pull); done` or something similar – Noufal Ibrahim Nov 11 '14 at 03:54
  • Please let me know what works and what doesn't. +1 – Aaron Hall Nov 11 '14 at 04:45
  • Do you want Python to execute those shell commands for you, or do you just want it to print them out so you can execute them yourself (via copy & paste)? – PM 2Ring Nov 11 '14 at 05:01
  • Basically I have 5 different git repos and I want to write a python script that allows me to pull all 5 repos at once instead of me doing so manually. – Jack_The_Ripper Nov 11 '14 at 06:52

1 Answers1

1

Use subprocess, os, and shlex. This should work, although you might require some minor tweaking:

import subprocess
import shlex
import os

# relative dir seems to work for me, no /'s or ~'s in front though
dir = 'Desktop/Git_Repo' 

# I did get fetch (but not pull) to work
cmd = shlex.split('git pull Git_Repo') 

# you need to give it a path to find git, this lets you do that.
env = os.environ 

subprocess.Popen(cmd, cwd=dir, env=env)

Also, you'll need your login preconfigured.

Aaron Hall
  • 291,450
  • 75
  • 369
  • 312