@@ -85,12 +85,15 @@ def _write_result(self, data, run_cookie):
85
85
86
86
return self ._url_path + '/' + file_name
87
87
88
- def _run_test (self , binfo ):
88
+ def _run_test (self , binfo , ref ):
89
89
self ._result_set (binfo ['branch' ], None )
90
90
91
91
start = datetime .datetime .now (datetime .UTC )
92
92
run_id_cookie = str (int (start .timestamp () / 60 ) % 1000000 )
93
- rinfo = {'run-cookie' : run_id_cookie }
93
+ rinfo = {
94
+ 'run-cookie' : run_id_cookie ,
95
+ 'branch-ref' : ref ,
96
+ }
94
97
results = self ._cb (binfo , rinfo , self ._cbarg )
95
98
end = datetime .datetime .now (datetime .UTC )
96
99
@@ -109,19 +112,23 @@ def _run_test(self, binfo):
109
112
110
113
self ._result_set (binfo ['branch' ], url )
111
114
112
- def _clean_old_branches (self , remote , current ):
113
- ret = subprocess .run ('git branch' ,
114
- cwd = self ._tree_path , shell = True ,
115
- capture_output = True , check = True )
115
+ def _find_branch (self , name ):
116
+ ret = subprocess .run (['git' , 'describe' , 'main' ],
117
+ check = False , capture_output = True )
118
+ if ret .returncode == 0 :
119
+ # git found a direct hit for the name, use as is
120
+ return name
116
121
117
- existing = set ([x .strip () for x in ret .stdout .decode ('utf-8' ).split ('\n ' )])
122
+ # Try to find the branch in one of the remotes (will return remote/name)
123
+ ret = subprocess .run (['git' , 'branch' , '-r' , '-l' , '*/' + name ],
124
+ cwd = self ._tree_path ,
125
+ capture_output = True , check = True )
118
126
119
- for b in remote :
120
- if b ["branch" ] in existing and b ["branch" ] != current :
121
- print ("Clean up old branch" , b ["branch" ])
122
- subprocess .run ('git branch -D ' + b ["branch" ],
123
- cwd = self ._tree_path , shell = True ,
124
- check = True )
127
+ branches = ret .stdout .decode ('utf-8' ).strip ()
128
+ branches = [x .strip () for x in branches .split ('\n ' )]
129
+ if len (branches ) != 1 :
130
+ print ("Unexpected number of branches found:" , branches )
131
+ return branches [0 ]
125
132
126
133
def _run_once (self ):
127
134
r = requests .get (self ._branches_url )
@@ -160,7 +167,8 @@ def _run_once(self):
160
167
print ("HEAD is still locked! Sleeping.." )
161
168
time .sleep (0.2 )
162
169
163
- subprocess .run ('git checkout ' + to_test ["branch" ],
170
+ ref = self ._find_branch (to_test ["branch" ])
171
+ subprocess .run ('git checkout --detach ' + ref ,
164
172
cwd = self ._tree_path , shell = True , check = True )
165
173
166
174
if self ._patches_path is not None :
@@ -169,8 +177,7 @@ def _run_once(self):
169
177
subprocess .run ('git apply -v {}' .format (realpath ),
170
178
cwd = self ._tree_path , shell = True )
171
179
172
- self ._clean_old_branches (branches , to_test ["branch" ])
173
- self ._run_test (to_test )
180
+ self ._run_test (to_test , ref )
174
181
175
182
def run (self ):
176
183
while self .life .next_poll ():
0 commit comments