MCPcopy Create free account
hub / github.com/isomorphic-git/isomorphic-git / getRemoteInfo

Function getRemoteInfo

src/api/getRemoteInfo.js:47–108  ·  view source on GitHub ↗
({
  http,
  onAuth,
  onAuthSuccess,
  onAuthFailure,
  corsProxy,
  url,
  headers = {},
  forPush = false,
})

Source from the content-addressed store, hash-verified

45 *
46 */
47export async function getRemoteInfo({
48 http,
49 onAuth,
50 onAuthSuccess,
51 onAuthFailure,
52 corsProxy,
53 url,
54 headers = {},
55 forPush = false,
56}) {
57 try {
58 assertParameter('http', http)
59 assertParameter('url', url)
60
61 const GitRemoteHTTP = GitRemoteManager.getRemoteHelperFor({ url })
62 const remote = await GitRemoteHTTP.discover({
63 http,
64 onAuth,
65 onAuthSuccess,
66 onAuthFailure,
67 corsProxy,
68 service: forPush ? 'git-receive-pack' : 'git-upload-pack',
69 url,
70 headers,
71 protocolVersion: 1,
72 })
73
74 // Note: remote.capabilities, remote.refs, and remote.symrefs are Set and Map objects,
75 // but one of the objectives of the public API is to always return JSON-compatible objects
76 // so we must JSONify them.
77 const result = {
78 capabilities: [...remote.capabilities],
79 }
80 // Convert the flat list into an object tree, because I figure 99% of the time
81 // that will be easier to use.
82 for (const [ref, oid] of remote.refs) {
83 const parts = ref.split('/')
84 const last = parts.pop()
85 let o = result
86 for (const part of parts) {
87 o[part] = o[part] || {}
88 o = o[part]
89 }
90 o[last] = oid
91 }
92 // Merge symrefs on top of refs to more closely match actual git repo layouts
93 for (const [symref, ref] of remote.symrefs) {
94 const parts = symref.split('/')
95 const last = parts.pop()
96 let o = result
97 for (const part of parts) {
98 o[part] = o[part] || {}
99 o = o[part]
100 }
101 o[last] = ref
102 }
103 return result
104 } catch (err) {

Calls 3

assertParameterFunction · 0.90
getRemoteHelperForMethod · 0.80
discoverMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…