commit 9a95f70e705a76f4a74500b76efea7ec3d966a55 (HEAD -> master)
Author: Nishanth Aravamudan <nish.aravamudan@canonical.com>
Date: Mon Aug 28 09:13:26 2017 -0700
lint: do not checkout a commit hash after modifying working tree
Instead, only do so if in detached HEAD state. Otherwise, checkout back
to the branch that HEAD points to.
LP: #1710035
diff --git a/gitubuntu/lint.py b/gitubuntu/lint.py
index 435e7f2..82984a8 100644
--- a/gitubuntu/lint.py
+++ b/gitubuntu/lint.py
@@ -419,7 +419,21 @@ class GitUbuntuLint:
return False
def tree_after_merge_changelogs(self, old, new):
- commitish_id = str(self.local_repo.raw_repo.head.resolve().peel().id)
+ if self.local_repo.raw_repo.head_is_detached:
+ head_string = str(
+ self.local_repo.raw_repo.head.resolve().peel().id
+ )
+ else:
+ for head in self.local_repo.local_branches:
+ if head.is_head():
+ head_string = head.branch_name
+ break
+ else:
+ logging.error("HEAD is not detached, but unable to "
+ "determine what local branch HEAD points to."
+ )
+ return None
+
merge_base_id = str(self.local_repo.raw_repo.merge_base(
self.local_repo.get_commitish(old).id,
self.local_repo.get_commitish(new).id)
@@ -452,10 +466,23 @@ class GitUbuntuLint:
f.close()
self.local_repo.git_run(["clean", "-f", "-d"])
self.local_repo.reset_commitish(new)
- self.local_repo.checkout_commitish(commitish_id)
+ self.local_repo.checkout_commitish(head_string)
def _tree_after_update_maintainer(self, commitish_string):
- commitish_id = str(self.local_repo.raw_repo.head.resolve().peel().id)
+ if self.local_repo.raw_repo.head_is_detached:
+ head_string = str(
+ self.local_repo.raw_repo.head.resolve().peel().id
+ )
+ else:
+ for head in self.local_repo.local_branches:
+ if head.is_head():
+ head_string = head.branch_name
+ break
+ else:
+ logging.error("HEAD is not detached, but unable to "
+ "determine what local branch HEAD points to."
+ )
+ return None
self.local_repo.checkout_commitish(commitish_string)
try:
run(["update-maintainer"])
@@ -473,7 +500,7 @@ class GitUbuntuLint:
finally:
self.local_repo.git_run(["clean", "-f", "-d"])
self.local_repo.reset_commitish(commitish_string)
- self.local_repo.checkout_commitish(commitish_id)
+ self.local_repo.checkout_commitish(head_string)
def _check_update_maintainer(self, commitish_string):
commitish = self.local_repo.get_commitish(commitish_string)
@@ -684,7 +711,7 @@ class GitUbuntuLint:
sys.exit(1)
else:
commitish_obj = self.local_repo.raw_repo.head
- if self.local_repo.head_is_detached:
+ if self.local_repo.raw_repo.head_is_detached:
commitish_string = 'HEAD'
else:
for head in self.local_repo.local_branches: