aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar jesopo2020-02-08 13:15:39 +0000
committerGravatar jesopo2020-02-08 13:21:29 +0000
commit4e9df2c552b9ea6212e223e38c8f5d49be3e6d42 (patch)
tree983f01126785e7166e27d2c59e02ad5b8841219d /src
parentspec[2] is a string, not an array of strings (diff)
signature
handle git being in a detached head state when getting current commit
Diffstat (limited to 'src')
-rw-r--r--src/ModuleManager.py5
-rw-r--r--src/utils/__init__.py21
2 files changed, 15 insertions, 11 deletions
diff --git a/src/ModuleManager.py b/src/ModuleManager.py
index dd378456..2ad086ea 100644
--- a/src/ModuleManager.py
+++ b/src/ModuleManager.py
@@ -272,9 +272,10 @@ class ModuleManager(object):
for key, value in magic.get_exports():
context_exports.add(key, value)
- current_commit = utils.git_commit(bot.directory)
+ branch, commit = utils.git_commit(bot.directory)
+
return LoadedModule(definition.name, module_title, module_object,
- context, import_name, definition.is_core, commit=current_commit)
+ context, import_name, definition.is_core, commit=commit)
def load_module(self, bot: "IRCBot.Bot", definition: ModuleDefinition
) -> LoadedModule:
diff --git a/src/utils/__init__.py b/src/utils/__init__.py
index 7180766b..55129137 100644
--- a/src/utils/__init__.py
+++ b/src/utils/__init__.py
@@ -127,17 +127,20 @@ def deadline_process(func: typing.Callable[[], DeadlineProcessReturnType],
else:
raise out # type: ignore
-def git_commit(bot_directory: str) -> typing.Optional[str]:
+def git_commit(bot_directory: str
+ ) -> typing.Tuple[typing.Optional[str], typing.Optional[str]]:
git_dir = os.path.join(bot_directory, ".git")
head_filepath = os.path.join(git_dir, "HEAD")
if os.path.isfile(head_filepath):
- ref = None
with open(head_filepath, "r") as head_file:
- ref = head_file.readline().split(" ", 1)[1].strip()
- branch = ref.rsplit("/", 1)[1]
+ ref_line = head_file.readline().strip()
+ if not ref_line.startswith("ref: "):
+ return None, ref_line
+ else:
+ ref = ref_line.split(" ", 1)[1]
+ branch = ref.rsplit("/", 1)[1]
- ref_filepath = os.path.join(git_dir, ref)
- if os.path.isfile(ref_filepath):
- with open(ref_filepath, "r") as ref_file:
- return ref_file.readline().strip()[:8]
- return None
+ ref_filepath = os.path.join(git_dir, ref)
+ with open(ref_filepath, "r") as ref_file:
+ return branch, ref_file.readline().strip()[:8]
+ return None, None