Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add git-sync command #153

Closed
wants to merge 7 commits into from
Closed

Add git-sync command #153

wants to merge 7 commits into from

Conversation

edvbld
Copy link
Member

@edvbld edvbld commented Sep 20, 2019

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

  • sh gradlew test passes on Linux x86_64
  • sh gradlew reproduce passes on Linux x86_64
  • Added two new unit tests
  • Manual testing of git sync

Thanks,
Erik

Progress

  • Change must not contain extraneous whitespace
  • Change must be properly reviewed

Approvers

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented Sep 20, 2019

👋 Welcome back ehelin! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request (refresh this page to view it).


var upstreamPullPath = remotes.contains(upstream) ?
Remote.toURI(repo.pullPath(upstream)) : URI.create(upstream);
var origin = "origin";
Copy link
Member

@JornVernee JornVernee Sep 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Member Author

@edvbld edvbld Sep 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Member

@JornVernee JornVernee Sep 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good!

@mlbridge
Copy link

@mlbridge mlbridge bot commented Sep 24, 2019

Webrevs

Copy link
Member

@rwestberg rwestberg left a comment

Looks good to me!

System.out.println("Skipping branch " + name);
continue;
}
System.out.print("Syncing " + upstream + "/" + name + " to " + origin + "/" + name + "... ");
Copy link
Member

@rwestberg rwestberg Sep 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to flush the PrintStream here?

Copy link
Member Author

@edvbld edvbld Sep 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, good idea, let me fix!

@openjdk openjdk bot removed the rfr label Sep 24, 2019
@openjdk
Copy link

@openjdk openjdk bot commented Sep 24, 2019

@edvbld This change can now be integrated. The commit message will be:

Add git-sync command

Reviewed-by: rwestberg, jvernee
  • If you would like to add a summary, use the /summary command.
  • To list additional contributors, use the /contributor command.

Since the source branch of this PR was last updated there have been 8 commits pushed to the master branch:

  • 13c4308: 102: Setting summary does not update the preview message
  • 7bdfab4: Add "binary" jcheck check
  • 15376a9: Add support for adding extra headers to mails sent to mailing lists
  • 2ab7e26: Future-proof mbox test
  • 016828d: webrev: fix indentation of removed binary file view
  • 5d474ee: Improve stripping of code blocks
  • cc79727: Add an issue link to RFR mails if the PR title contains one
  • 0132f0e: Add support for adding an issue when formatting the commit message

Since there are no conflicts, your changes will automatically be rebased on top of the above commits when integrating. If you prefer to do this manually, please merge master into your branch first.

  • To integrate this PR with the above commit message, type /integrate in a new comment.

@openjdk openjdk bot added the ready label Sep 24, 2019
@edvbld
Copy link
Member Author

@edvbld edvbld commented Sep 24, 2019

/integrate

@openjdk openjdk bot closed this Sep 24, 2019
@openjdk openjdk bot added integrated and removed ready labels Sep 24, 2019
@openjdk
Copy link

@openjdk openjdk bot commented Sep 24, 2019

@edvbld The following commits have been pushed to master since your change was applied:

Your commit was automatically rebased without conflicts.
Pushed as commit 6ba889e.

@mlbridge
Copy link

@mlbridge mlbridge bot commented Sep 24, 2019

Mailing list message from duke duke@openjdk.java.net

Changeset: 6ba889e
Author: Erik Helin
Date: 2019-09-24 12:13:22 +0000
URL: https://git.openjdk.java.net/skara/commit/6ba889e2

Add git-sync command

Reviewed-by: rwestberg, jvernee

! cli/build.gradle
! cli/src/main/java/org/openjdk/skara/cli/GitFork.java
! cli/src/main/java/org/openjdk/skara/cli/GitPr.java
! cli/src/main/java/org/openjdk/skara/cli/GitSkara.java

  • cli/src/main/java/org/openjdk/skara/cli/GitSync.java
  • cli/src/main/java/org/openjdk/skara/cli/Remote.java
    ! jcheck/src/test/java/org/openjdk/skara/jcheck/TestRepository.java
    ! skara.gitconfig
    ! vcs/src/main/java/org/openjdk/skara/vcs/ReadOnlyRepository.java
  • vcs/src/main/java/org/openjdk/skara/vcs/Reference.java
    ! vcs/src/main/java/org/openjdk/skara/vcs/git/GitRepository.java
    ! vcs/src/main/java/org/openjdk/skara/vcs/hg/HgRepository.java
    ! vcs/src/main/resources/ext.py
    ! vcs/src/test/java/org/openjdk/skara/vcs/RepositoryTests.java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants