Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions guw/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,11 @@ def _sync_at(self, tmpdir, backup, local, features, prev_feature, interactive):
# Now remove every feature that must be removed
self.config["features"] = [f for f in self.config["features"] if f["status"] != "_remove"]
# Make target branch be the last feature
last_feature = self.config["features"][-1]
if last_feature:
if last_feature["status"] != "integrated":
self._copy(repo, last_feature, self._get_target_feature(), backup)
else:
logger.info("All features already integrated, nothing to do")
last_feature = next(reversed([f for f in self.config["features"] if f["status"] != "integrated"]), None)
if not last_feature:
last_feature = self._get_source_feature()
self._copy(repo, last_feature, self._get_target_feature(), backup)

# If we are syncing from upstream, make sure to update source too
upstream_feature = self._get_upstream_feature()
if (
Expand Down Expand Up @@ -383,13 +382,9 @@ def remove(self, backup, keep, local, folder, to_remove, interactive=False):
if not feature:
logger.critical(f"Feature {feature} not found")
return
if not idx:
prev_feature = self._get_source_feature()
else:
prev_feature = self.config["features"][idx - 1]
feature["status"] = "_remove"
# Sync it again
self._sync(backup, keep, local, folder, self.config["features"][idx:], prev_feature, interactive=interactive)
self._sync(backup, keep, local, folder, self.config["features"], prev_feature=None, interactive=interactive)
# Dump the new toml
self.dump()

Expand Down
37 changes: 36 additions & 1 deletion tests/test_remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def setUp(self):
def cleanUp(self):
shutil.rmtree(self.tmpdir)

def test_remove(self):
def test_remove_last(self):
config = """
[[remotes]]
name = "origin"
Expand Down Expand Up @@ -65,3 +65,38 @@ def test_remove(self):
# Check the proper order of the commits, like git log --pretty=%s
commits = [x.summary for x in repo.iter_commits("example1-final")]
self.assertEqual(commits, expected_commits)

def test_remove_prev_feature_is_integrated(self):
config = """
[[remotes]]
name = "origin"
url = "https://github.com/fluendo/git-upstream-workflow.git"

[target]
remote = "origin"
branch = "example1-final"

[source]
remote = "origin"
branch = "example1-main"

[[features]]
remote = "origin"
name = "example1-feature1"
pr = "https://github/fluendo/git-upstream-workflow/pull-requests/10"
status = "integrated"

[[features]]
remote = "origin"
name = "example1-feature1-fixup"
pr = "https://github/fluendo/git-upstream-workflow/pull-requests/10"
status = "pending"
"""
expected_commits = ["Initial commit"]
guw = GUW(tomli.loads(config))
guw.remove(False, True, True, self.tmpdir, "example1-feature1-fixup")
repo = git.Repo(self.tmpdir)
# Check the proper order of the commits, like git log --pretty=%s
commits = [x.summary for x in repo.iter_commits("example1-final")]

self.assertEqual(commits, expected_commits)
Loading