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

Zpf/tracking multiple branch #43

Closed 1216114309zpf closed 2 years ago

1216114309zpf commented 2 years ago

Currently git-repo doesn't support creating merge-requests from a same branch to multiple remote branch with the same change. For example, first create a merge-request from local branch topic to remote branch master, and switch topic's remote tracking branch to remote branch main, then execute pr and you got remind "no change in project . (branch master) since last upload":

IT-C02YW0UGLVDL:sky zhaopengfei$ git pr
对象计数中: 3, 完成.
Delta compression using up to 8 threads.
压缩对象中: 100% (2/2), 完成.
写入对象中: 100% (3/3), 289 bytes | 289.00 KiB/s, 完成.
Total 3 (delta 0), reused 0 (delta 0)
remote: 2021/12/06 19:56:43 debug logging disabled
remote: +-------------------------------------------------------------------------------------+
remote: | Merge Request #23168 was created or updated.                                        |
remote: | View merge request at URL:                                                          |
remote: | https://codeup.aliyun.com/6183ea91e84c82e792916acc/sky/merge_request/23168 |
remote: +-------------------------------------------------------------------------------------+
remote: 2021/12/06 19:56:45 debug logging disabled
To https://codeup.aliyun.com/6183ea91e84c82e792916acc/sky.git
 * [new branch]      master -> refs/for/master/master

----------------------------------------------------------------------
IT-C02YW0UGLVDL:sky zhaopengfei$ 
IT-C02YW0UGLVDL:sky zhaopengfei$ 
IT-C02YW0UGLVDL:sky zhaopengfei$ git branch -u origin/main
分支 master 设置为跟踪来自 origin 的远程分支 main。
IT-C02YW0UGLVDL:sky zhaopengfei$ 
IT-C02YW0UGLVDL:sky zhaopengfei$ git pr
NOTE: no change in project . (branch master) since last upload
NOTE: no branches ready for upload

The reason behind is that git-repo has a local cache to avoid creating seem merge-request repeatedly. Specifically, git-repo keeps published status (tip commit id) of each local branch in a special ref "refs/published/\<branch>", each time we create a merge-request from a local branch "topic", git-repo first check if "topic's" tip commit is equal to the commit kept in ref "refs/published/topic", if they are equal, git-repo will reject the creating mr request and remind us "no change in project . (branch ***) since last upload", otherwise, git-repo will create a mr and keeps/updates "topic's" tip commit id in ref "refs/published/topic". Above cache mechanism means you cannot create mr from a specific local branch to multiple remote branch with the same change.

To remove above limitation, this pr changes above cache mechanism, it keeps published status of merge-requests instead of local branches. Specifically, when you create a mr from a local branch to a remote branch, it keeps local branch's tip commit id in a special ref "refs/published/\<local branch>/\<remote branch>".

jiangxin commented 2 years ago

Add a new option "--re-run" for git-repo, so user can ignore the recorded published ref, and continue to upload. Usage:

git repo upload --re-run

See #46