Bug 514052 - LsRemoteCommand does not report symref information
Summary: LsRemoteCommand does not report symref information
Status: RESOLVED FIXED
Alias: None
Product: JGit
Classification: Technology
Component: JGit (show other bugs)
Version: 4.5   Edit
Hardware: All All
: P3 normal with 2 votes (vote)
Target Milestone: 5.10   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-03-22 06:13 EDT by Stephen Connolly CLA
Modified: 2020-11-26 16:49 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stephen Connolly CLA 2017-03-22 06:13:46 EDT
As of Git 1.8.5 the symref information is reported as a capability:

https://github.com/git/git/commit/7171d8c15f919c760d52f814a0aee1b1253385b1

If you want to get this information, you are required to do all sorts of evil reflection, e.g.:

                Class<?> basePackConnection = BasePackFetchConnection.class.getSuperclass();
                Field remoteCapablities = basePackConnection.getDeclaredField("remoteCapablities");
                remoteCapablities.setAccessible(true);
                try (Transport transport = Transport.open(repo, url)) {
                    transport.setCredentialsProvider(getProvider());
                    try (FetchConnection fc = transport.openFetch()) {
                        fc.getRefs();
                        if (fc instanceof BasePackFetchConnection) {
                            Object o = remoteCapablities.get(fc);
                            if (o instanceof Set) {
                                boolean hackWorked = false;
                                for (String capability: (Set<String>)o) {
                                    if (capability.startsWith("symref=")) {
                                        hackWorked = true;
                                        int index = capability.indexOf(":", 7);
                                        if (index != -1) {
                                            references.put(capability.substring(7, index), capability.substring(index+1));
                                        }
                                    }
                                }
                                if (hackWorked) {
                                    return references;
                                }
                            }
                        }
                    }
                } catch (URISyntaxException | NotSupportedException | TransportException e) {
                    // ignore this is a total hack
                }

Please add the ability to get the symbolic reference information from LsRemoteCommand
Comment 1 Stephen Connolly CLA 2017-03-22 06:16:52 EDT
Note this feature is relevant to the Jenkins project: https://github.com/jenkinsci/git-client-plugin/pull/236 and https://issues.jenkins-ci.org/browse/JENKINS-40834
Comment 2 Stephen Connolly CLA 2017-03-22 06:18:12 EDT
The Jenkins plugins are currently restricted to JGit 4.5.x due to the requirement for Java 7 bytecode on the current baseline versions of Jenkins that the plugins are maintained against, so we would request that the fix be added to both 4.5.x and 4.6.x
Comment 3 Mark Waite CLA 2018-02-17 11:49:42 EST
Jenkins git client plugin will soon update to JGit 4.10.0 or later.  If this is implemented, it only needs to be implemented on the current development stream, not backported to JGit 4.5.
Comment 4 Mark Waite CLA 2020-02-08 17:47:05 EST
Jenkins git client plugin is now using JGit 5.6.0. If this is implemented, it is enough to implement on the current JGit.
Comment 6 Thomas Wolf CLA 2020-11-26 16:49:09 EST
(In reply to Eclipse Genie from comment #5)
> Gerrit change https://git.eclipse.org/r/c/jgit/jgit/+/171875 was merged to
> [master].
> Commit:
> http://git.eclipse.org/c/jgit/jgit.git/commit/
> ?id=9ebbfe93bb3ba0ea170d330fe227f1d8182d7d64

This change makes LsRemoteCommand return SymbolicRefs for symrefs advertised through capabilities, if the symref target is also in the refs listed.