mirror of https://github.com/CIRCL/AIL-framework
Fix IndexError in get_last_tag_from_remote function
This commit adds a check to ensure that the output from the subprocess command in the get_last_tag_from_remote function has a sufficient number of lines before attempting to access specific indices. This change prevents the IndexError that occurred when the git command's output was shorter than expected.pull/604/head
parent
38157f8a01
commit
81f9a860d4
|
@ -129,17 +129,25 @@ def get_last_tag_from_local(verbose=False):
|
||||||
print('{}{}{}'.format(TERMINAL_RED, process.stderr.decode(), TERMINAL_DEFAULT))
|
print('{}{}{}'.format(TERMINAL_RED, process.stderr.decode(), TERMINAL_DEFAULT))
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
# Get last local tag
|
# Get last remote tag
|
||||||
def get_last_tag_from_remote(verbose=False):
|
def get_last_tag_from_remote(verbose=False):
|
||||||
if verbose:
|
if verbose:
|
||||||
print('retrieving last remote tag ...')
|
print('retrieving last remote tag ...')
|
||||||
#print('git ls-remote --tags')
|
#print('git ls-remote --tags')
|
||||||
|
|
||||||
process = subprocess.run(['git', 'ls-remote', '--tags'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
process = subprocess.run(['git', 'ls-remote', '--tags'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
if process.returncode == 0:
|
if process.returncode == 0:
|
||||||
res = process.stdout.split(b'\n')[-2].split(b'/')[-1].replace(b'^{}', b'').decode()
|
output_lines = process.stdout.split(b'\n')
|
||||||
if verbose:
|
if len(output_lines) > 1:
|
||||||
print(res)
|
# Assuming we want the second-to-last line as before
|
||||||
return res
|
res = output_lines[-2].split(b'/')[-1].replace(b'^{}', b'').decode()
|
||||||
|
if verbose:
|
||||||
|
print(res)
|
||||||
|
return res
|
||||||
|
else:
|
||||||
|
if verbose:
|
||||||
|
print("No tags found or insufficient output from git command.")
|
||||||
|
return ''
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if verbose:
|
if verbose:
|
||||||
|
|
Loading…
Reference in New Issue