git sync
: Update upstreams of branches if upstreams are deleted
#624
Replies: 1 comment 3 replies
-
Thanks for the suggestion. I'm a little bit surprised that the code review process works this way. If I understand correctly, Could this behavior be implemented by looking at all current branches, finding their nearest ancestor branches, and setting the upstream branch to that nearest ancestor? You might be able to solve this problem right now for yourself by adding a command like this to your for branch in $(git query --branches 'draft () & branches()'); do
# NB: might be empty if there is no previous branch:
previous_branch=$(git query --branches "heads(branches() & ancestors($branch^))")
echo "Previous branch of $branch is: $previous_branch"
done |
Beta Was this translation helpful? Give feedback.
-
This is mainly to support the use of
git cl
as used in the Chromium project.git cl
uses a "pull request (changelist) per branch" workflow, allowing for dependent pull requests by setting the "upstream" of a branch. In fact, depot_tools - the collection of commands thatgit cl
is included in - has a command (git-rebase-update
) which closely mimics the behaviour ofgit-branchless sync
, and handles the following issue.To show an example of the issue:
Setup commands
We have a
main
branch, one branchcl1
withmain
as upstream, andcl2
withcl1
as upstream.Let's say that
cl1
was merged into upstream (main
):Then, when doing a
git sync
, the branchcl1
disappears as it's merged in (as expected):$ git sync Attempting rebase in-memory... [1/2] Skipped commit (was already applied upstream): 287ab78 CL 1 [2/2] Committed as: 1378396 CL 2 branchless: processing 2 updates: branch cl1, branch cl2 branchless: processing 2 rewritten commits branchless: creating working copy snapshot branchless: running command: git checkout main Switched to branch 'main' branchless: processing checkout In-memory rebase succeeded. Synced 287ab78 CL 1 $ git sl ⋮ ◆ 1bccdd3 40s (ᐅ main) CL 1 (merged in) ┃ ◯ 1378396 9s (cl2) CL 2
but
cl2
still has an upstream ofcl1
, which is now gone!This is a feature request to update branch upstreams when
git sync
deletes branches - in this case, updating the upstream ofcl2
to bemain
.This also applies for chains of branches: for example,
main
is the upstream ofcl1
which is the upstream ofcl2
which is the upstream ofcl3
. If bothcl1
andcl2
were applied upstream,cl3
should have an upstream ofmain
after agit-branchless sync
.Beta Was this translation helpful? Give feedback.
All reactions