Ubuntu Pastebin

Paste from nacc at Mon, 28 Aug 2017 16:13:37 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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:
Download as text