Commit 4f51354a authored by Spyros Argyropoulos's avatar Spyros Argyropoulos Committed by Frank Siegert
Browse files

Check if DSID is used in other branches

* will check if a DSID is being used by any other branch in the remote and if so throw an error
* this feature is used by both the commit script and the CI
parent 3bd23229
Pipeline #1489174 skipped
......@@ -95,6 +95,25 @@ def check_naming(jofile):
return generator_list[0]
# function to check if a DSID is free
def isFreeDSID(dsid):
# Get current branch
command="git rev-parse --abbrev-ref HEAD"
# Get all remote branches excluding current branch
command="git for-each-ref --format='%(refname)' refs/remotes/origin/"
branches=list(filter(lambda s: currentBranch not in s, os.popen(command).read().strip().split("\n")))
for branch in branches:
command="git ls-tree -r --name-only {branch} | awk -F'/' '/[0-9]{{3}}xxx/ {{print $2}}' | sort -u".format(branch=branch)
occupiedDSIDs=list(map(int, filter(None,os.popen(command).read().strip().split("\n"))))
if int(dsid) in occupiedDSIDs:
print("\tERROR: {dsid} used in branch: {branch}".format(dsid=dsid, branch=branch))
return False
return True
# function to suggest DSID
# increment is used to handle several DSIDs
def findSmallestFreeDSID(minDSID,maxDSID,currentDSID,increment):
......@@ -125,8 +144,14 @@ def check_dsidrange(generatorName,dsid,increment):
# Check if DSID is in the correct range
if int(dsid) >= minDSID and int(dsid) <= maxDSID:
print("\tOK: correct DSID range")
# Check if the DSID is not used by any other branch in remote
if isFreeDSID(dsid):
print("\tOK: {dsid} not used by other branches".format(dsid=dsid))
return 1
return 0
print("\tERROR: DSID:{dsid}, generator:{generatorName} => allowed DSID range {minDSID} - {maxDSID}".format(dsid=dsid, generatorName=generatorName, minDSID=minDSID, maxDSID=maxDSID))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment