Skip to content

Commit

Permalink
Add upstream section to distinguish between our own "main" and the up…
Browse files Browse the repository at this point in the history
…stream "main".

The "sync" command will use it if defined, "source" otherwise. For the other commands, "source" will always be used.
  • Loading branch information
rgonzalezfluendo committed Dec 9, 2024
1 parent daac04f commit 12f6e76
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,12 @@ status = "pending"
The configuration must include the list of remotes under the `[[remotes]]` section. This is useful
when the upstream branch is done in a git provider like GitLab but the development is done in GitHub.

There are two special sections, `[source]` and `[target]`. The `[source]` section defines the branch
the project you want to contribute to uses as the main stable branch. The `[target]` section defines
the branch that should hold all the features.
There are three special sections, `[target]`, `[source]` and `[upstream]`. The `[target]` section defines the branch
that should hold all the features. The `[source]` section defines the branch the project you want to contribute to
uses as base. The `[upstream]` section defines the branch the project you want to contribute to uses as the main
branch, this branch is not fixed and depends on the project. The goal of having two bases is for when there are upstream
changes that break the sync, and a fixed base is wanted to continue making integrations in the project. The `[upstream]`
section is opcional and `[source]` section is used if not defined.

The `[[features]]` section defines the list of features you want to include upstream (the `target` branch).
Each feature has the following key/value pairs:
Expand Down
24 changes: 18 additions & 6 deletions guw/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ def _backup_name(self, name):
return backup_name

def _get_upstream_feature(self):
if "upstream" not in self.config:
return self._get_source_feature()

return {
"remote": self.config["upstream"]["remote"],
"name": self.config["upstream"]["branch"],
}

def _get_source_feature(self):
return {
"remote": self.config["source"]["remote"],
"name": self.config["source"]["branch"],
Expand Down Expand Up @@ -194,9 +203,12 @@ def _sync_at(self, tmpdir, backup, local, features, prev_feature):
# Push every branch
self._push(repo, local)

def _sync(self, backup, keep, local, folder, features=None, prev_feature=None):
def _sync(self, backup, keep, local, folder, features=None, prev_feature=None, from_upstream=False):
features = features if features else self.config["features"]
prev_feature = prev_feature if prev_feature else self._get_upstream_feature()
if prev_feature:
prev_feature = prev_feature
else:
prev_feature = self._get_upstream_feature() if from_upstream else self._get_source_feature()
tmpdir = folder if folder else tempfile.mkdtemp()
exception = None
try:
Expand All @@ -212,7 +224,7 @@ def _sync(self, backup, keep, local, folder, features=None, prev_feature=None):
exit(1)

def sync(self, backup, keep, local, folder):
self._sync(backup, keep, local, folder)
self._sync(backup, keep, local, folder, from_upstream=True)

def dump(self):
print(tomli_w.dumps(self.config))
Expand Down Expand Up @@ -308,7 +320,7 @@ def remove(self, backup, keep, local, folder, to_remove):
logger.critical(f"Feature {feature} not found")
return
if not idx:
prev_feature = self._get_upstream_feature()
prev_feature = self._get_source_feature()
else:
prev_feature = self.config["features"][idx - 1]
feature["status"] = "_remove"
Expand All @@ -323,7 +335,7 @@ def update(self, backup, keep, local, folder, from_branch, feature_name):
logger.critical(f"Feature {feature_name} not found")
return
if not idx:
prev_feature = self._get_upstream_feature()
prev_feature = self._get_source_feature()
else:
prev_feature = self.config["features"][idx - 1]

Expand All @@ -343,7 +355,7 @@ def integrate(self, backup, keep, local, folder, feature_name):
logger.critical(f"The feature {feature_name} is not in merging state")
return
if not idx:
prev_feature = self._get_upstream_feature()
prev_feature = self._get_source_feature()
else:
prev_feature = self.config["features"][idx - 1]
# Now the feature must be on merged to sync properly
Expand Down

0 comments on commit 12f6e76

Please sign in to comment.