1
0
Fork 0
mirror of https://github.com/clockfort/GitHub-Backup.git synced 2025-03-23 00:00:05 +01:00

added support for extra git arguments

This commit is contained in:
Steffen Vogel 2013-08-02 00:50:54 +02:00
parent ee763dfcb6
commit b68463bc6a

View file

@ -32,15 +32,14 @@ def init_parser():
parser.add_argument("backupdir", help="The folder where you want your backups to go") parser.add_argument("backupdir", help="The folder where you want your backups to go")
parser.add_argument("-c","--cron", help="Use this when running from a cron job", action="store_true") parser.add_argument("-c","--cron", help="Use this when running from a cron job", action="store_true")
parser.add_argument("-m","--mirror", help="Create a bare mirror", action="store_true") parser.add_argument("-m","--mirror", help="Create a bare mirror", action="store_true")
parser.add_argument("-g","--git", help="Pass extra arguments to git", default="")
return parser return parser
def process_repo(repo, args): def process_repo(repo, args):
if args.cron: if args.cron:
git_args = "-q" args.git += "--quit"
else:
git_args = ""
if not args.cron: if not args.cron:
print("Processing repo: %s"%(repo.full_name)) print("Processing repo: %s"%(repo.full_name))
@ -50,18 +49,20 @@ def process_repo(repo, args):
if os.access(config,os.F_OK): if os.access(config,os.F_OK):
if not args.cron: if not args.cron:
print("Repo already exists, let's try to update it instead") print("Repo already exists, let's try to update it instead")
os.system("cd %s/%s"%(args.backupdir, repo.name)) os.system("cd %s/%s"%(args.backupdir, repo.name))
if args.mirror: if args.mirror:
git_args += " --prune" args.git += " --prune"
os.system("git fetch %s"%(git_args,)) os.system("git fetch %s"%(args.git,))
else: else:
os.system("git pull %s"%(git_args,)) os.system("git pull %s"%(args.git,))
else: # Repo doesn't exist, let's clone it else: # Repo doesn't exist, let's clone it
if args.mirror: if args.mirror:
git_args += " --mirror" args.git += " --mirror"
os.system('git clone %s %s %s/%s'%(git_args, repo.git_url, args.backupdir, repo.name)) os.system('git clone %s %s %s/%s'%(args.git, repo.git_url, args.backupdir, repo.name))
if __name__ == "__main__": if __name__ == "__main__":
main() main()