Skip to content

Instantly share code, notes, and snippets.

@seudut
Created January 5, 2016 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seudut/841782c86d9e1f5d8da8 to your computer and use it in GitHub Desktop.
Save seudut/841782c86d9e1f5d8da8 to your computer and use it in GitHub Desktop.
import sys,os,subprocess
def get_file_mode_change (branch1, branch2):
cmd = 'git diff --summary ' + branch1 + '..' + branch2 + ' | grep "mode change" | ' + " awk '{ print $6 }' "
output = subprocess.check_output (cmd, shell=True)
return output.splitlines()
def get_file_deleted (branch1, branch2):
cmd = 'git diff --name-status ' + branch1 + '..' + branch2 + ' | grep "^D" | ' + " awk '{ print $2 }' "
output = subprocess.check_output (cmd, shell=True)
return output.splitlines()
def is_content_same (branch1, branch2):
cmd = 'git diff ' + branch1 + '..' + branch2 + ' --exit-code > /dev/null 2>&1';
return not subprocess.call(cmd, shell=True)
def mina(nn, retry=3):
if nn < 5:
return True
if retry < 0:
return False
nn = nn + 1;
return mina (nn, retry-1)
if __name__ == '__main__':
print str(sys.argv[1])
commit = sys.argv[1]
aa = mina(5, 2)
print aa
if aa:
print "true"
else:
print "false"
time.sleep(5);
raise Exception("=====");
os.chdir("adaptation_resilience")
export_branch = "pppp_" + commit
## update svn
cmd = 'git svn fetch svn'
print cmd
print subprocess.check_output (cmd, shell=True)
## reset up_branch
cmd = 'git checkout up_branch'
print subprocess.check_output (cmd, shell=True)
cmd = 'git reset --hard ' + commit
print subprocess.check_output (cmd, shell=True)
## create import branch
cmd = 'git checkout -b ' + export_branch + ' git-svn '
print subprocess.check_output (cmd, shell=True)
msg_commit = " = commit == " + commit
count_commit = 0;
### check file mode change
files_mode = []
file_mode = get_file_mode_change("", "up_branch")
if file_mode:
print " ======= file mode changed ====== "
for file in file_mode:
cmd = 'git checkout up_branch -- ' + file
print subprocess.check_output (cmd, shell=True)
cmd = 'git commit -m "' + msg_commit + ' ++ file mode change"'
print subprocess.check_output (cmd, shell=True)
count_commit = count_commit + 1
### check file deleted
file_deleted = []
file_deleted = get_file_deleted("", "up_branch")
if file_deleted:
print "======== file deleted ========"
for file in file_deleted:
cmd = 'git rm ' + file
print subprocess.check_output (cmd, shell=True)
cmd = 'git commit -m "' + msg_commit + ' ++ deleted file"'
print subprocess.check_output (cmd, shell=True)
count_commit = count_commit + 1
## merge all commit above into one git commit
cmd = 'git merge --strategy=recursive -X theirs ' + commit + ' -m "' + msg_commit + ' merge " '
print subprocess.check_output (cmd, shell=True)
if count_commit > 0:
count_commit = count_commit + 1;
cmd = 'git reset --soft HEAD~' + str(count_commit)
print subprocess.check_output (cmd, shell=True)
cmd = 'git commit -m "' + msg_commit + ' ++ merged ++' + str(count_commit) + ' "'
print subprocess.check_output (cmd, shell=True)
### check if branch same
if is_content_same (export_branch, "up_branch"):
print "======= ALL is OK ======== do svn commit =====" + commit + "===="
cmd = 'git svn dcommit --no-rebase '
print subprocess.check_output (cmd, shell=True)
print "======= Successfully " + commit + "===="
else:
raise Exception(" Error: ***** still has difference **** on " + commit + " ")
### svn update and check
### cmd = 'git svn fetch svn'
### print cmd
### print subprocess.check_output (cmd, shell=True)
###
### if is_content_same ("git-svn", "up_branch"):
### print " ======== update successfully ====="
### else:
### print " Error ******************** "
###
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment