RFR: Add git-sync command

Erik Helin ehelin at openjdk.org
Tue Sep 24 10:24:14 UTC 2019


On Tue, 24 Sep 2019 09:52:06 GMT, Robin Westberg <rwestberg 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 144:
> 
>> 143:             }
>> 144:             System.out.print("Syncing " + upstream + "/" + name + " to " + origin + "/" + name + "... ");
>> 145:             var fetchHead = repo.fetch(upstreamPullPath, branch.hash().hex());
> 
> Do you need to flush the PrintStream here?

Probably, good idea, let me fix!

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


More information about the skara-dev mailing list