RFR: Add git-sync command

Erik Helin ehelin at openjdk.org
Tue Sep 24 09:46:16 UTC 2019

On Tue, 24 Sep 2019 09:38:49 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:

> On Tue, 24 Sep 2019 09:38:45 GMT, Erik Helin <ehelin at openjdk.org> wrote:
>> Hi all,
>> this commits adds the new `git sync` command which is useful for syncing a personal fork with its upstream repository. `git sync` supports both a remote and URL as a argument, for example:
>> $ git sync upstream
>> Syncing upstream/master with origin/master... done
>> $ git sync https://github.com/openjdk/skara
>> Syncing https://github.com/openjdk/skara/master with origin/master... done
>> The remote can also be configured in `.git/config` (or `~/.gitconfig`) as in:
>> [sync]
>>        remote = upstream
>> I also added two options, `--pull` and `--fetch`, that will pull and/or fetch the current branch. This is a shorthand for `git sync && git pull`. Since `git fork` sets the `sync.remote` in `.git/config` (local for the repository) a user now only has to write to fork an upstream repository, sync the branches and update their local copy:
>> $ git fork https://github.com/openjdk/skara
>> $ cd skara
>> $ git sync --pull
>> The syncing leaves no trace in the local repository, I'm only using `FETCH_HEAD` in the refspec when pushing to the personal fork.
>> ## Testing
>> - [x] `sh gradlew test` passes on Linux x86_64
>> - [x] `sh gradlew reproduce` passes on Linux x86_64
>> - [x] Added two new unit tests
>> - [x] Manual testing of `git sync`
>> Thanks,
>> Erik
>> ----------------
>> Commits:
>>  - 62268c27: Set sync configuration with git-fork
>>  - b4add8cc: Add --fetch and --pull options, also allow remote to be configured
>>  - c3692ab8: Add sync to GitSkara as well
>>  - 6d751a06: Add alias for git-sync in skara.gitconfig
>>  - 9a77ebc5: Add git-sync command
>> Changes: https://git.openjdk.java.net/skara/pull/153/files
>>  Webrev: https://webrevs.openjdk.java.net/skara/153/webrev.00
>>   Stats: 508 lines in 14 files changed: 465 ins; 40 del; 3 mod
>>   Patch: https://git.openjdk.java.net/skara/pull/153.diff
>>   Fetch: git fetch https://git.openjdk.java.net/skara pull/153/head:pull/153
> cli/src/main/java/org/openjdk/skara/cli/GitSync.java line 127:
>> 126:             Remote.toURI(repo.pullPath(upstream)) : URI.create(upstream);
>> 127:         var origin = "origin";
>> 128:         var originPushPath = Remote.toURI(repo.pushPath(origin));
> I think the fork remote name should be a CLI option as well, maybe in the gitconfig as well (e.g. I have named it `fork` for some of my local repos)

I thought about that, the hard part is what to call the option. I guess my preference would be `--to`, so that a user wishing to sync to another remote types `git sync --to fork upstream`. But then we should probably make the input at position 0 a flag instead, so the command reads `git sync --from upstream --to fork` instead. Without a `--to` flag the command reads `git sync --from upstream` which seems ok to me. Both `sync.form` and `sync.to` should be configurable in gitconfig of course. What do you think?

PR: https://git.openjdk.java.net/skara/pull/153

More information about the skara-dev mailing list