Skip to content

Commit

Permalink
removes branch-check before git-push code.
Browse files Browse the repository at this point in the history
  • Loading branch information
birkin committed Jan 17, 2025
1 parent 24169bc commit 135dd4f
Showing 1 changed file with 3 additions and 30 deletions.
33 changes: 3 additions & 30 deletions lib_compilation_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,8 @@ def copy_new_compile_to_codebase(self, compiled_requirements: Path, project_path
subprocess.run(command, cwd=project_path)
# subprocess.run(['git', 'commit', '-m', 'auto-update of requirements'], cwd=project_path)
## run a git-push via subprocess ------------------------
branch = self.fetch_branch_data(project_path)
if branch not in ['detached', 'project_branch_not_found']:
command = ['git', 'push', 'origin', branch]
log.debug(f'command, given valid branch was found: ``{command}``')
else:
command = ['git', 'push', 'origin']
log.debug(f'command, given valid branch was not found: ``{command}``')
command = ['git', 'push', 'origin', 'main']
log.debug(f'git-push command, ``{command}``')
subprocess.run(command, cwd=project_path)
except Exception as e:
git_problem_message = f'Error with git-commit or git-push; error: ``{e}``'
Expand All @@ -142,28 +137,6 @@ def copy_new_compile_to_codebase(self, compiled_requirements: Path, project_path
log.debug(f'problem_message: ``{problem_message}``')
return problem_message

def fetch_branch_data(self, project_path: Path) -> str:
"""
Fetches branch-data by reading the `.git/HEAD` file (avoiding calling git via subprocess due to `dubious ownership` issue).
Called by copy_new_compile_to_codebase()
"""
log.debug('starting fetch_branch_data')
git_dir = project_path / '.git'
try:
## read HEAD file to find the project branch ------------
head_file = git_dir / 'HEAD'
ref_line = head_file.read_text().strip()
if ref_line.startswith('ref:'):
project_branch = ref_line.split('/')[-1] # extract the project_branch name
else:
project_branch = 'detached'
except FileNotFoundError:
log.warning('no `.git` directory or HEAD file found.')
project_branch = 'project_branch_not_found'
except Exception:
log.exception('other problem fetching project_branch data')
project_branch = 'project_branch_not_found'
log.debug(f'project_branch: ``{project_branch}``')
return project_branch
## end def copy_new_compile_to_codebase()

## end class CompiledComparator

0 comments on commit 135dd4f

Please sign in to comment.