alibaba / git-repo-go

git-repo is a command-line tool for centralized workflow, can work with Gerrit, AGit-Flow compatible servers. It is written in Golang, and it can be installed easily without further dependency. It provides an easy-to-use solution for multiple repositories which is introduced by Android repo first, and it can also work with a single repository.
https://git-repo.info/
Apache License 2.0
262 stars 60 forks source link

'git repo sync' get an error of 'is published (but not merged)' after 'git pr' #22

Closed guestliu closed 3 years ago

guestliu commented 3 years ago

Run a bash, we get an error of "Error: branch my_patch is published (but not merged)"

#!/bin/bash
SCRIPT_DIR="$(cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd)"
cd $SCRIPT_DIR
REPO=$HOME/bin/repo

set -ex

DIR=`pwd`/test-sync
rm -rf $DIR && mkdir -p $DIR
cd $DIR

git repo init -u git@gitlab.alibaba-inc.com:alicpp2/test-repo.git
git repo sync -j 32
git repo start my_patch --all
ls -l

cd test_repo1-x
uuid >> INSTALL
git add INSTALL
git commit -m 'a new commit'
echo x | git pr

cd $DIR
rm -rf xtmp
git clone git@gitlab.alibaba-inc.com:alicpp2/test-repo1.git xtmp/test-repo1
cd xtmp/test-repo1
uuid >> README
git add README
git commit -m 'change readme'
git push origin HEAD:master

cd $DIR/test_repo1-x
git repo sync

image

This situation is very common. If we work on a patch for weeks, we often need to run 'git pr' to generate the merge request for the reviewer and handle with the challenges, do some code changes and run 'git pr' again. Sometimes we must run 'git repo sync' to rebase the newest code but we get an error.

In our team development-faq, I suggest the solution like this image image

It's awful.

jiangxin commented 3 years ago

Like gerrit repo, git-repo-go saved the reference which the user published in a special reference "refs/published/{NAME}" in the repository. This saved special reference is used to prevent duplicate git repo upload. But running git repo sync which rebase the working tree to upstream may break the matching of the special published reference.

To work around this issue, you can start a new branch by running git repo start --all {topic-name}

jiangxin commented 3 years ago

One reasonable solution for this case may be:

  1. Always allow sync local workspace.
  2. After local changed commits have been rebased to new upstream, check differences between the rebase commits and cached latest uploaded commits by check the patch-id.
jiangxin commented 3 years ago

See pull request #24 .