@@ -96,38 +96,46 @@ def test_heads(self, rwrepo):
96
96
# END for each head
97
97
98
98
# verify REFLOG gets altered
99
- if False :
100
- head = rwrepo .head
101
- orig_head = head .orig_head ()
102
- cur_head = head .ref
103
- cur_commit = cur_head .commit
104
- pcommit = cur_head .commit .parents [0 ].parents [0 ]
105
- head .ref = pcommit # detach head
106
- assert orig_head .commit == cur_commit
107
-
108
- # even if we set it through its reference - chaning the ref
109
- # will adjust the orig_head, which still points to cur_commit
110
- head .ref = cur_head
111
- assert orig_head .commit == pcommit
112
- assert head .commit == cur_commit == cur_head .commit
113
-
114
- cur_head .commit = pcommit
115
- assert head .commit == pcommit
116
- assert orig_head .commit == cur_commit
117
-
118
- # with automatic dereferencing
119
- head .commit = cur_commit
120
- assert orig_head .commit == pcommit
121
-
122
- # changing branches which are not checked out doesn't affect the ORIG_HEAD
123
- other_head = Head .create (rwrepo , 'mynewhead' , pcommit )
124
- assert other_head .commit == pcommit
125
- assert orig_head .commit == pcommit
126
- other_head .commit = pcommit .parents [0 ]
127
- assert orig_head .commit == pcommit
128
-
129
- # TODO: Need changing a ref changes HEAD reflog as well if it pointed to it
130
-
99
+ head = rwrepo .head
100
+ cur_head = head .ref
101
+ cur_commit = cur_head .commit
102
+ pcommit = cur_head .commit .parents [0 ].parents [0 ]
103
+ hlog_len = len (head .log ())
104
+ blog_len = len (cur_head .log ())
105
+ head .set_reference (pcommit , 'detached head' )
106
+ # one new log-entry
107
+ thlog = head .log ()
108
+ assert len (thlog ) == hlog_len + 1
109
+ assert thlog [- 1 ].oldhexsha == cur_commit .hexsha
110
+ assert thlog [- 1 ].newhexsha == pcommit .hexsha
111
+
112
+ # the ref didn't change though
113
+ assert len (cur_head .log ()) == blog_len
114
+
115
+ # head changes once again, cur_head doesn't change
116
+ head .set_reference (cur_head , 'reattach head' )
117
+ assert len (head .log ()) == hlog_len + 2
118
+ assert len (cur_head .log ()) == blog_len
119
+
120
+ # adjusting the head-ref also adjust the head, so both reflogs are
121
+ # altered
122
+ cur_head .set_commit (pcommit , 'changing commit' )
123
+ assert len (cur_head .log ()) == blog_len + 1
124
+ assert len (head .log ()) == hlog_len + 3
125
+
126
+
127
+ # with automatic dereferencing
128
+ head .set_commit (cur_commit , 'change commit once again' )
129
+ assert len (head .log ()) == hlog_len + 4
130
+ assert len (cur_head .log ()) == blog_len + 2
131
+
132
+ # a new branch has just a single entry
133
+ other_head = Head .create (rwrepo , 'mynewhead' , pcommit , msg = 'new head created' )
134
+ log = other_head .log ()
135
+ assert len (log ) == 1
136
+ assert log [0 ].oldhexsha == pcommit .NULL_HEX_SHA
137
+ assert log [0 ].newhexsha == pcommit .hexsha
138
+
131
139
132
140
def test_refs (self ):
133
141
types_found = set ()
@@ -509,4 +517,5 @@ def test_todo(self):
509
517
# delete deletes the reflog
510
518
# create creates a new entry
511
519
# set_reference and set_commit and set_object use the reflog if message is given
520
+ # if there is no actual head-change, don't do anything
512
521
self .fail ()
0 commit comments