Skip to content

Commit 5db0e44

Browse files
authored
Use merges while getting branch uptodate; automatically update PRs (#8)
* Use merges while getting branch uptodate; automatically update PRs * update * update
1 parent 65339f8 commit 5db0e44

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

gitstack.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ def operate(self, operation: str, args: List[str]) -> None:
114114
assert len(args) == 1
115115
parent = args[0]
116116
self.track_current_branch(parent)
117-
elif operation in {"su", "submit"}:
117+
elif operation in {"pr"}:
118118
assert len(args) == 0
119-
self.submit_stack()
119+
self.create_prs()
120120
elif operation in {"s", "sync"}:
121121
assert len(args) == 0
122122
self.sync()
@@ -134,8 +134,9 @@ def print_stack(self):
134134
)
135135
)
136136

137-
def submit_stack(self):
137+
def create_prs(self):
138138
"""Submit the stack starting at the current branch going down"""
139+
branch = self.original_branch
139140
while branch != self.trunk:
140141
p = subprocess.run(
141142
[
@@ -152,7 +153,13 @@ def submit_stack(self):
152153
)
153154
has_pr = bool(p.stdout.decode().strip())
154155
if has_pr:
155-
pass
156+
subprocess.run(
157+
["git", "push"],
158+
check=True,
159+
stdout=sys.stdout.buffer,
160+
stderr=sys.stderr.buffer,
161+
)
162+
print(f"Updated PR for {branch}")
156163
else:
157164
parent = self.gitstack[branch]
158165
subprocess.run(
@@ -161,9 +168,17 @@ def submit_stack(self):
161168
stdout=sys.stdout.buffer,
162169
stderr=sys.stderr.buffer,
163170
)
171+
print(f"Created PR for {branch}")
164172

165173
branch = self.switch_to_parent()
166174

175+
subprocess.run(
176+
["git", "switch", self.original_branch],
177+
check=True,
178+
stdout=sys.stdout.buffer,
179+
stderr=sys.stderr.buffer,
180+
)
181+
167182
def create_branch(self, branch: str, parent) -> None:
168183
"""Create new branch and add to gitstack"""
169184
subprocess.run(
@@ -180,7 +195,7 @@ def track_current_branch(self, parent):
180195
print(f"Branch {parent} does not exist")
181196
return
182197

183-
branch = git_get_current_branch()
198+
branch = self.original_branch
184199
if branch == parent:
185200
print("Branch cannot be its own parent")
186201
return
@@ -342,12 +357,12 @@ def _check_and_rebase(self, branch: str) -> None:
342357
)
343358
current_base_sha = p.stdout.decode().strip()
344359
if current_parent_sha == current_base_sha:
345-
logger.info(
346-
"Branch %s doesn't need to be rebased on top of %s", branch, parent
360+
print(
361+
f"Branch {branch} up-to-date with {parent}", branch, parent
347362
)
348363
return
349-
logger.info("Rebasing %s on top of %s", branch, parent)
350-
subprocess.run(["git", "rebase", parent, branch], check=True)
364+
print(f"Merging {parent} into {branch}")
365+
subprocess.run(["git", "merge", parent], check=True)
351366

352367
def _get_trunk(self):
353368
"""Get name of trunk based on possible candidates"""

0 commit comments

Comments
 (0)