Skip to content

Commit

Permalink
fix: set upstream for new branches
Browse files Browse the repository at this point in the history
  • Loading branch information
AAriam committed Oct 24, 2023
1 parent 4876c2b commit 65db724
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespaces = true
# ----------------------------------------- Project Metadata -------------------------------------
#
[project]
version = "0.0.0.dev144"
version = "0.0.0.dev145"
name = "RepoDynamics"
dependencies = [
"packaging >= 23.2, < 24",
Expand Down
15 changes: 8 additions & 7 deletions src/repodynamics/actions/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ def action_meta(self):
typ=self.metadata["commit"]["secondary_action"]["meta_sync"]["type"],
title="Sync dynamic files with meta content",
)
self.commit(message=str(commit_msg), stage="all", push=True)
self.commit(message=str(commit_msg), stage="all", push=True, set_upstream=action == "pull")
if action == "pull":
pull_data = self.api.pull_create(
head=self.git.current_branch_name(),
Expand Down Expand Up @@ -705,7 +705,7 @@ def action_hooks(self):
modified = hooks_output["modified"]
# Push/amend/pull if changes are made and action is not 'fail' or 'report'
if action not in ["fail", "report"] and modified:
self.push(amend=action == "amend")
self.push(amend=action == "amend", set_upstream=action == "pull")
if action == "pull":
pull_data = self.api.pull_create(
head=self.git.current_branch_name(),
Expand Down Expand Up @@ -1262,16 +1262,17 @@ def commit(
message: str = "",
stage: Literal['all', 'staged', 'unstaged'] = 'all',
amend: bool = False,
push: bool = False
push: bool = False,
set_upstream: bool = False
):
commit_hash = self.git.commit(message=message, stage=stage, amend=amend)
if amend:
self._amended = True
if push:
commit_hash = self.push()
commit_hash = self.push(set_upstream=set_upstream)
return commit_hash

def tag_version(self, ver: str | PEP440SemVer, msg: str = ""):
def tag_version(self, ver: str | PEP440SemVer, msg: str = ""):
tag_prefix = self.metadata["tag"]["group"]["version"]["prefix"]
tag = f"{tag_prefix}{ver}"
if not msg:
Expand All @@ -1280,8 +1281,8 @@ def tag_version(self, ver: str | PEP440SemVer, msg: str = ""):
self._tag = tag
return

def push(self, amend: bool = False):
new_hash = self.git.push(force_with_lease=self._amended or amend)
def push(self, amend: bool = False, set_upstream: bool = False):
new_hash = self.git.push(set_upstream=set_upstream, force_with_lease=self._amended or amend)
self._amended = False
if new_hash and self.git.current_branch_name() == self.ref_name:
self._hash_latest = new_hash
Expand Down
8 changes: 6 additions & 2 deletions src/repodynamics/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ def __init__(
self.set_user(username=self._COMMITTER_USERNAME, email=self._COMMITTER_EMAIL)
return

def push(self, target: str = None, ref: str = None, force_with_lease: bool = False) -> str | None:
def push(self, target: str = None, ref: str = None, set_upstream: bool = False, force_with_lease: bool = False) -> str | None:
command = ["git", "push"]
if target:
if set_upstream:
if not target:
self._logger.error("No target provided while setting upstream.")
command.extend(["--set-upstream", target])
elif target:
command.append(target)
if ref:
command.append(ref)
Expand Down

0 comments on commit 65db724

Please sign in to comment.