This Python script does following activities:
clone repo, as provided from the list
creating a new branch "jenkinsMigrate"
rename Jenkinsfile to Jenkinsfile.migrate
push code to GitHub in a new branch.
NOTE: credentials were configured already.
import git
import os
import subprocess
gitUrl = "https://*****"
cwd = "*****"
with open("migrateList.txt", "r") as file:
for line in file:
#configure gitUri for each repository
gitUri = gitUrl + line.strip() + ".git"
try:
global repo
repo = git.Repo.clone_from(gitUri, cwd + line.strip())
except:
print(" directory already available")
os.chdir(cwd + line.strip())
#checkout new branch for migration
repo.git.checkout('-b', "jenkinsMigrate")
subprocess.call(["git", "mv", "Jenkinsfile", "Jenkinsfile.migrate"])
repo.git.add(update=True)
repo.index.commit("jenkins migration")
origin = repo.remote(name='origin')
#push new branch to github
subprocess.call(["git","push", "--set-upstream", "origin", "jenkinsMigrate"])
subprocess.call(["cd", ".."])
Sample text file:
$ cat migrateList.txt
repo1
repo2
repo3
repo4
This is a working code, but all I am looking for is to maintain consistency in the commands that I use. eg: For some of the git commands that I have used are from gitpython module where as others are invoked with shell commands. Apart from these any other suggestions are welcome.
Thanks!
UPDATE 1: python - 2.7.10
gitPython module
git
pacakage are you using? Probably not git, but maybe GitPython? \$\endgroup\$