1
1
mirror of https://github.com/chubin/cheat.sh.git synced 2024-11-22 01:40:48 +03:00

Compare commits

...

2 Commits

Author SHA1 Message Date
Igor Chubin
7f769d6f36 Add -- to git commands to avoid ambiguities (fixes #303) 2022-04-17 12:01:47 +00:00
Igor Chubin
7c5bfa5d9c Fix keyword-based search (#323)
* Fixes directories handling in git-based repos
* Fixes a minor bug in tldr-adapter
2022-04-17 12:01:46 +00:00
3 changed files with 10 additions and 9 deletions

View File

@ -43,7 +43,7 @@ class RepositoryAdapter(Adapter):
self._cheatsheet_files_prefix,
topic)
if os.path.exists(filename):
if os.path.exists(filename) and not os.path.isdir(filename):
answer = self._format_page(open(filename, 'r').read())
else:
# though it should not happen
@ -124,7 +124,7 @@ class GitRepositoryAdapter(RepositoryAdapter): #pylint: disable=abstract-meth
raise RuntimeError(
"Do not known how to handle this repository: %s" % cls._repository_url)
return ['git', 'rev-parse', '--short', 'HEAD']
return ['git', 'rev-parse', '--short', 'HEAD', "--"]
@classmethod
def save_state(cls, state):
@ -157,6 +157,6 @@ class GitRepositoryAdapter(RepositoryAdapter): #pylint: disable=abstract-meth
The list is used to invalidate the cache.
"""
current_state = cls.get_state()
if current_state is None:
return ['git', 'ls-tree', '--full-tree', '-r', '--name-only', 'HEAD']
return ['git', 'diff', '--name-only', current_state, 'HEAD']
if not current_state:
return ['git', 'ls-tree', '--full-tree', '-r', '--name-only', 'HEAD', "--"]
return ['git', 'diff', '--name-only', current_state, 'HEAD', "--"]

View File

@ -73,15 +73,16 @@ class Tldr(GitRepositoryAdapter):
and as soon as anything is found, format and return it.
"""
search_order = ['common', 'linux', 'osx', 'sunos', 'windows']
search_order = ['common', 'linux', 'osx', 'sunos', 'windows', "android"]
local_rep = self.local_repository_location()
ext = self._cheatsheet_files_extension
filename = None
for subdir in search_order:
filename = os.path.join(
_filename = os.path.join(
local_rep, 'pages', subdir, "%s%s" % (topic, ext))
if os.path.exists(filename):
if os.path.exists(_filename):
filename = _filename
break
if filename:

View File

@ -118,7 +118,7 @@ def _update_adapter(adptr):
errorcode, output = _run_cmd(cmd)
if errorcode:
_log("\nERROR:\n---\n" + output + "\n---\nCould not update %s" % adptr)
_log("\nERROR:\n---%s\n" % output.decode("utf-8") + "\n---\nCould not update %s" % adptr)
return False
# Getting current repository state