Merge pull request #4521 from wschaeferB/4690-MatchAutopsyBranchToTskBranch

4690 match autopsy branch to tsk branch
This commit is contained in:
Richard Cordovano 2019-02-10 08:07:44 -05:00 committed by GitHub
commit 2452b87b8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,9 +12,12 @@ import subprocess
import xml.etree.ElementTree as ET
TSK_HOME=os.getenv("TSK_HOME",False)
ORIGIN_OWNER="origin"
DEVELOP_BRANCH='develop'
passed = 1
def getSleuthkitBranchList():
def getSleuthkitBranchList(branchOwner):
# Returns the list of sleuthkit branches
cmd = ['git','branch','-a']
retdir = os.getcwd()
@ -22,12 +25,12 @@ def getSleuthkitBranchList():
output = subprocess.check_output(cmd)
branches = []
for branch in output.strip().split():
if branch.startswith('remotes/origin'):
if branch.startswith('remotes/'+branchOwner):
branches.append(branch.split('/')[2])
os.chdir(retdir)
return branches
def gitSleuthkitCheckout(branch):
def gitSleuthkitCheckout(branch, branchOwner):
'''
Checksout sleuthkit branch
Args:
@ -36,7 +39,16 @@ def gitSleuthkitCheckout(branch):
# passed is a global variable that gets set to non-zero integer
# When an error occurs
global passed
cmd = ['git','checkout',branch]
if (branchOwner==ORIGIN_OWNER):
cmd = ['git','checkout', branch]
else:
#add the remotes
checkout=['git','checkout','-b',branchOwner+'-'+branch]
passed = subprocess.call(checkout, stdout=sys.stdout,cwd=TSK_HOME)
cmd = ['git','pull', "/".join(["https://github.com", branchOwner, "sleuthkit.git"]), branch]
if passed != 0: #0 would be success
#unable to create new branch return instead of pulling
return
passed = subprocess.call(cmd,stdout=sys.stdout,cwd=TSK_HOME)
def parseXML(xmlFile):
@ -64,14 +76,16 @@ def main():
TRAVIS=os.getenv("TRAVIS",False)
APPVEYOR=os.getenv("APPVEYOR",False)
if TRAVIS == "true":
CURRENT_BRANCH=os.getenv("TRAVIS_BRANCH",False)
CURRENT_BRANCH=os.getenv("TRAVIS_PULL_REQUEST_BRANCH",False)
BRANCH_OWNER=os.getenv("TRAVIS_PULL_REQUEST_SLUG", False).split('/')[0]
elif APPVEYOR:
CURRENT_BRANCH=os.getenv("APPVEYOR_REPO_BRANCH",False)
CURRENT_BRANCH=os.getenv("APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH",False)
BRANCH_OWNER=os.getenv("APPVEYOR_PULL_REQUEST_HEAD_REPO_NAME", False).split('/')[0]
else:
cmd=['git','rev-parse','--abbrev-ref','HEAD']
output = subprocess.check_output(cmd)
CURRENT_BRANCH=output.strip()
BRANCH_OWNER=ORIGIN_OWNER
# If we are in an Autopsy release branch, then use the
# info in TSKVersion.xml to find the corresponding TSK
# release branch. For other branches, we don't always
@ -79,14 +93,17 @@ def main():
if CURRENT_BRANCH.startswith('release'):
version = parseXML('TSKVersion.xml')
RELEASE_BRANCH = "release-"+version
gitSleuthkitCheckout(RELEASE_BRANCH)
# Check if the same branch exists in TSK (develop->develop, custom1->custom1, etc.)
elif CURRENT_BRANCH in getSleuthkitBranchList():
gitSleuthkitCheckout(CURRENT_BRANCH)
# Otherwise, default to develop
gitSleuthkitCheckout(RELEASE_BRANCH, BRANCH_OWNER)
#If it failed try the origin release branch
if passed != 0:
gitSleuthkitCheckout('develop')
gitSleuthkitCheckout(RELEASE_BRANCH, ORIGIN_OWNER)
# Check if the same branch exists in TSK (develop->develop, custom1->custom1, etc.)
else:
gitSleuthkitCheckout(CURRENT_BRANCH, BRANCH_OWNER)
# Otherwise, default to origin develop
if passed != 0:
gitSleuthkitCheckout(DEVELOP_BRANCH, ORIGIN_OWNER)
if passed != 0:
print('Error checking out a Sleuth Kit branch')