Get all branches before cloning a repo - jgit

I'm writing an utility in swing that show all my projects and should let me clone a specific repo and also select the branch I want to switch to, once the cloning process is finished.
The only problem is that in order to show the branches as far as I can see you need to clone the repo first.
Is there a workaround for that?

You can list tags/heads on remote repositories via the following snippet:
Collection<Ref> refs = Git.lsRemoteRepository()
.setHeads(true)
.setTags(true)
.setRemote(REMOTE_URL)
.call();
See also this ready-to-run snippet in the jgit-cookbook

Related

Specify dependency branch or commit ID in Swift PM's Package.swift

Is there a way to define dependency in Package.swift that would point at a certain branch latest commit, or even to just a specific commit ID (just like it is possible with Carthage)?
Use case would be, let's say I have a library repo where I would like to branch out and make some changes, and then be able to test them out in a dependent project.
As of Swift 4 you can use .branch() and .revision() as described in PackageDescription.md.
It is possible.
Go to project
Click on "Package Dependencies" Tab
Double click on the package you want to change the branch of
Specify the branch/commit.
Not yet, but swiftpm team is working on. Now you must specify a package version when declaring a dependency.
import PackageDescription
let package = Package(
name: "Example",
dependencies: [
.Package(url: "https://github.com/somePackage", "1.0.0")
]
)
In the future it will be possible, there was a discussion to add Version Locking but its not accepted and implemented yet.
For your use case you can fork the repo, do the changes, test them and then add a version tag to your fork. Now it's much more easier to do changes with Editable Packages functionality.

the concepts of git ignore and not commiting, but still using, global variables

I'm a bit of a newbie, but already running apps with Meteor.js. Since I'm now working with API keys I'm finally realizing that security is a thing, and so I placed my keys in a settings.json, and am instructed not to commit, or to .gitignore the file. But despite reading the documentation, this all seems very counter-intuitive. If I need the variables to make my HTTP requests, then how can my app possibly function without adding my keys, in some form, to the repo? I know the answer is "it can," but how? (in general terms, I don't need a Meteor specialist yet) .
Typing this question out makes me feel pretty ignorant for the stage I'm at, but the docs out there for some reason are not clarifying this for me.
You can generate the file with sensitive information on git checkout.
That is called a smudge script, part of a content filter driver, using using .gitattributes declaration.
(image from "Customizing Git - Git Attributes", from "Pro Git book")
That 'smudge' script( that you have to write) would need to:
fetch the right key (from a source outside the repo, that way no risk to add and push by mistake)
generate the settings.json, using a tracked manifest template settings.json.tpl with placeholder value in it to replace.
That means:
the template settings.json.tpl is added to the git repo
the generate file settings.json is declared in the .gitignore file and never versioned.

Explain the concept of branch, trunk, in the context of source code repositories (like Subversion, VCS, VSS)

concept of branch, trunk/*
Context of Source Code repositories
A trunk is the main code base and is the one that began when the project started and until the present.
A branch is a copy of the code derived from trunk and that is used for applying changes to the code. If the changes are accepted, they are merged back into the trunk.

Checkout a tag in headless state with JGit

Attempting to use JGit to checkout an existing tag on an existing repository. Preferably left in a headless state. The command should be as simple as:
git checkout clever-tag-name
However, the JGit incantation:
String tagName = "clever-tag-name";
Git.open(new File(repoPath)).checkout().setName(tagName).call();
Results in a series of checkout errors. This usage seems like it should be trivial. The command line version has no issues given my repo's current state.
Here's an example of the checkout error I am referring to:
Exception in thread "main" org.eclipse.jgit.api.errors.CheckoutConflictException: Checkout conflict with files:
.idea/copyright/profiles_settings.xml
...
at org.eclipse.jgit.dircache.DirCacheCheckout.doCheckout(DirCacheCheckout.java:416)
at org.eclipse.jgit.dircache.DirCacheCheckout.checkout(DirCacheCheckout.java:397)
at org.eclipse.jgit.api.CheckoutCommand.call(CheckoutCommand.java:261)
... 6 more
Any help would be greatly appreciated.

JGit fetch() don't update tag

My remote repository got a tag moved to a new commit.
I run:
git.fetch().setTagOpt(TagOpt.FETCH_TAGS)
.setRemote("remoteURL")
.setRefSpecs(new RefSpec("+refs/heads/*:refs/remotes/origin/*"))
.call();
FetchResult includes a REJECTED update.
The equivalent cli git -t ... does not behave this way.
Don't want to argue cli vs JGit, but wonder how I can do a fetch to update tags?
Seems I have to get org.eclipse.jgit.storage.file.RefUpdate with force=true, but don't know how... and don't realy want to duplicate all FetchProcess code :'(
This was a known problem that was fixed in JGit 3.0, see bug 388095.
As for a solution that works with the earlier releases, adding an explicit refspec for tags helps:
+refs/tags/*:refs/tags/*

Resources