[Diff] Changed the name of the link

- It now tries with the branch, then the tag and finally what the user
  named.

Related to #276
This commit is contained in:
Salvador E. Tropea 2022-09-06 08:55:15 -03:00
parent b704c2ab41
commit f603301d59
2 changed files with 23 additions and 4 deletions

View File

@ -144,11 +144,13 @@ def debug_output(res):
logger.debug('- Output from command: '+res.stdout.decode())
def run_command(command, change_to=None):
def run_command(command, change_to=None, just_raise=False):
logger.debug('Executing: '+shlex.join(command))
try:
res = run(command, check=True, stdout=PIPE, stderr=STDOUT, cwd=change_to)
except CalledProcessError as e:
if just_raise:
raise
logger.error('Running {} returned {}'.format(e.cmd, e.returncode))
debug_output(e)
exit(FAILED_EXECUTE)

View File

@ -23,6 +23,7 @@ from hashlib import sha1
import os
import re
from shutil import rmtree, copy2
from subprocess import CalledProcessError
from tempfile import mkdtemp, NamedTemporaryFile
from .error import KiPlotConfigurationError
from .gs import GS
@ -146,10 +147,10 @@ class DiffOptions(BaseOptions):
def cache_file(self, name=None):
return self.cache_pcb(name) if self.pcb else self.cache_sch(name)
def run_git(self, cmd, cwd=None):
def run_git(self, cmd, cwd=None, just_raise=False):
if cwd is None:
cwd = self.repo_dir
return run_command([self.git_command]+cmd, change_to=cwd)
return run_command([self.git_command]+cmd, change_to=cwd, just_raise=just_raise)
def stash_pop(self, cwd=None):
# We don't know if we stashed anything (push always returns 0)
@ -207,6 +208,22 @@ class DiffOptions(BaseOptions):
logger.debug('- '+res)
return res
def get_git_point_desc(self, user_name):
branch = self.run_git(['rev-parse', '--abbrev-ref', 'HEAD'])
if branch == 'HEAD':
# Detached
# Try to find the name relative to a tag
try:
name = self.run_git(['describe', '--tags', '--dirty'], just_raise=True)
except CalledProcessError:
logger.debug("Can't find a tag name")
name = None
if not name:
name = user_name
else:
name = branch
return '{}({})'.format(self.run_git(['rev-parse', '--short', 'HEAD']), name)
def cache_git(self, name):
self.stashed = False
self.checkedout = False
@ -242,7 +259,7 @@ class DiffOptions(BaseOptions):
self.run_git(ops+['--recurse-submodules', name])
self.checkedout = True
# A short version of the current hash
self.git_hash = '{}({})'.format(name_ori, self.run_git(['rev-parse', '--short', 'HEAD']))
self.git_hash = self.get_git_point_desc(name_ori)
# Populate the cache
hash = self.cache_file()
finally: