grgit icon indicating copy to clipboard operation
grgit copied to clipboard

Pull specific repository and refspec

Open eaaltonen opened this issue 7 years ago • 4 comments

I would need functionality similar to git pull from the command line:

  • pull specific repository
  • pull specific refspec (commit, branch or tag)

The obvious place to put them would seem to be org.ajoberstar.grgit.operation.PullOp.

I can try to come up with a pull request, but please comment on the idea.

eaaltonen avatar May 31 '17 13:05 eaaltonen

PullOp (which maps to JGit's PullCommand) already supports:

  • remote (which maps to the JGIt remote supporting remote names or uris)
  • branch (which maps to the JGit remoteBranchName)

From their doc, it doesn't imply much flexibility beyond the branch name. If you need full refspec support, you could separate it into a fetch and merge. FetchOp definitely supports refspecs.

ajoberstar avatar May 31 '17 23:05 ajoberstar

remote did indeed support also URIs.

I had some success using fetch + merge using a fixed ref of the form refs/heads/<branch>.

grgit.fetch('refSpecs': [ref], 'remote': uri, 'tagMode': FetchOp.TagMode.AUTO)
grgit.merge('head': 'FETCH_HEAD', 'mode': MergeOp.Mode.ONLY_FF)

This allowed me to pull from a dynamically determined remote repository without risk of overwriting any configured remotes.

However, this approach failed when trying to pull a commit by SHA, which jgit apparently does not support yet. https://bugs.eclipse.org/bugs/show_bug.cgi?id=517858

I will have to use cgit for now, but for someone wanting to pull branches and tags I supposed the above would work.

eaaltonen avatar Jun 06 '17 12:06 eaaltonen

Thanks for the follow up. I've tagged this as one waiting on JGit.

ajoberstar avatar Jun 09 '17 01:06 ajoberstar

Confirming that the JGit bug is still open as of 10/22/2017.

ajoberstar avatar Oct 22 '17 20:10 ajoberstar