Skip to content

Commit 1ca8aad

Browse files
refactor: extract remote branch parsing to helper and clean up debug code
Moves parsing logic for 'git remote show origin' to utilitymethods.py to eliminate duplication and removes accidental debug print. Signed-off-by: guptapratykshh <pratykshgupta9999@gmail.com>
1 parent 3da58ce commit 1ca8aad

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

augur/tasks/git/util/facade_worker/facade_worker/repofetch.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import os
3131
import pathlib
3232
import sqlalchemy as s
33-
from .utilitymethods import update_repo_log, get_absolute_repo_path
33+
from .utilitymethods import update_repo_log, get_absolute_repo_path, parse_remote_default_branch
3434
from sqlalchemy.orm.exc import NoResultFound
3535
from augur.application.db.models.augur_data import *
3636
from augur.application.db.models.augur_operations import CollectionStatus
@@ -351,12 +351,7 @@ def git_repo_updates(facade_helper, repo_git):
351351

352352
remotedefault = ""
353353
if return_code_remote == 0 and output:
354-
for line in output.split('\n'):
355-
if "HEAD branch" in line:
356-
parts = line.split(":", 1)
357-
if len(parts) > 1:
358-
remotedefault = parts[1].strip()
359-
break
354+
remotedefault = parse_remote_default_branch(output)
360355

361356
facade_helper.log_activity(
362357
'Verbose', f'remote default getting checked out is: {remotedefault}.')
@@ -429,12 +424,7 @@ def git_repo_updates(facade_helper, repo_git):
429424

430425
remotedefault = ""
431426
if return_code_remote == 0 and output:
432-
for line in output.split('\n'):
433-
if "HEAD branch" in line:
434-
parts = line.split(":", 1)
435-
if len(parts) > 1:
436-
remotedefault = parts[1].strip()
437-
break
427+
remotedefault = parse_remote_default_branch(output)
438428

439429
try:
440430

@@ -498,7 +488,7 @@ def git_repo_updates(facade_helper, repo_git):
498488

499489
cmdpull2 = ["git", "-C", absolute_path, "pull"]
500490

501-
print(cmdpull2)
491+
502492
return_code, _ = facade_helper.run_git_command(
503493
cmdpull2,
504494
timeout=600, # 10 minutes for git pull

augur/tasks/git/util/facade_worker/facade_worker/utilitymethods.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,4 +219,16 @@ def update_facade_scheduling_fields(repo_git, weight, commit_count):
219219
session.commit()
220220

221221

222-
222+
def parse_remote_default_branch(git_remote_output):
223+
"""
224+
Parses the output of 'git remote show origin' to find the HEAD branch.
225+
"""
226+
if not git_remote_output:
227+
return ""
228+
229+
for line in git_remote_output.split('\\n'):
230+
if "HEAD branch" in line:
231+
parts = line.split(":", 1)
232+
if len(parts) > 1:
233+
return parts[1].strip()
234+
return ""

0 commit comments

Comments
 (0)