1
1
// @ts-check
2
-
import { getConfig } from '../commands/getConfig.js'
2
+
import '../commands/typedefs.js'
3
+
4
+
import { currentBranch } from '../commands/currentBranch.js'
5
+
import { GitConfigManager } from '../managers/GitConfigManager.js'
3
6
import { GitRefManager } from '../managers/GitRefManager.js'
4
7
import { GitRemoteManager } from '../managers/GitRemoteManager.js'
5
8
import { GitShallowManager } from '../managers/GitShallowManager.js'
@@ -42,12 +45,12 @@ import { writeUploadPackRequest } from '../wire/writeUploadPackRequest.js'
42
45
* @param {string} args.gitdir
43
46
* @param {string|void} [args.url]
44
47
* @param {string} [args.corsProxy]
45
-
* @param {string} [args.ref = 'HEAD']
46
-
* @param {string[]} [args.refs = [ref]]
48
+
* @param {string} [args.ref]
49
+
* @param {string} [args.remoteRef]
50
+
* @param {string} [args.remote]
47
51
* @param {boolean} [args.singleBranch = false]
48
52
* @param {boolean} [args.noGitSuffix = false]
49
53
* @param {boolean} [args.tags = false]
50
-
* @param {string} [args.remote]
51
54
* @param {number} [args.depth]
52
55
* @param {Date} [args.since]
53
56
* @param {string[]} [args.exclude = []]
@@ -72,10 +75,10 @@ export async function fetch ({
72
75
onAuthSuccess,
73
76
onAuthFailure,
74
77
gitdir,
75
-
ref = 'HEAD',
76
-
refs = [ref],
77
-
remote,
78
-
url,
78
+
ref: _ref,
79
+
remoteRef: _remoteRef,
80
+
remote: _remote,
81
+
url: _url,
79
82
noGitSuffix = false,
80
83
corsProxy,
81
84
username,
@@ -92,33 +95,31 @@ export async function fetch ({
92
95
prune = false,
93
96
pruneTags = false
94
97
}) {
95
-
// Lookup remote tracking branch.
96
-
remote =
97
-
remote ||
98
-
(await getConfig({
99
-
fs,
100
-
gitdir,
101
-
path: `branch.${ref}.remote`
102
-
})) ||
103
-
'origin'
104
-
// Set missing values
98
+
const ref = _ref || (await currentBranch({ fs, gitdir }))
99
+
if (typeof ref === 'undefined') {
100
+
throw new GitError(E.MissingRequiredParameterError, {
101
+
parameter: 'ref'
102
+
})
103
+
}
104
+
const config = await GitConfigManager.get({ fs, gitdir })
105
+
// Figure out what remote to use.
106
+
const remote =
107
+
_remote || (await config.get(`branch.${ref}.remote`)) || 'origin'
108
+
// Lookup the URL for the given remote.
109
+
const url = _url || (await config.get(`remote.${remote}.url`))
105
110
if (typeof url === 'undefined') {
106
-
url = await getConfig({
107
-
fs,
108
-
gitdir,
109
-
path: `remote.${remote}.url`
111
+
throw new GitError(E.MissingRequiredParameterError, {
112
+
parameter: 'remote OR url'
110
113
})
111
-
// TODO: throw better error
112
-
if (typeof url === 'undefined') {
113
-
throw new GitError(E.MissingRequiredParameterError, {
114
-
parameter: 'remote OR url'
115
-
})
116
-
}
117
114
}
115
+
// Figure out what remote ref to use.
116
+
const remoteRef =
117
+
_remoteRef || (await config.get(`branch.${ref}.merge`)) || ref
118
118
119
119
if (corsProxy === void 0) {
120
-
corsProxy = await getConfig({ fs, gitdir, path: 'http.corsProxy' })
120
+
corsProxy = await config.get('http.corsProxy')
121
121
}
122
+
122
123
let auth = { username, password, token, oauth2format }
123
124
const GitRemoteHTTP = GitRemoteManager.getRemoteHelperFor({ url })
124
125
const remoteHTTP = await GitRemoteHTTP.discover({
@@ -158,7 +159,7 @@ export async function fetch ({
158
159
}
159
160
// Figure out the SHA for the requested ref
160
161
const { oid, fullref } = GitRefManager.resolveAgainstMap({
161
-
ref,
162
+
ref: remoteRef,
162
163
map: remoteRefs
163
164
})
164
165
// Filter out refs we want to ignore: only keep ref we're cloning, HEAD, branches, and tags (if we're keeping them)
@@ -195,7 +196,7 @@ export async function fetch ({
195
196
// Come up with a reasonable list of oids to tell the remote we already have
196
197
// (preferably oids that are close ancestors of the branch heads we're fetching)
197
198
const haveRefs = singleBranch
198
-
? refs
199
+
? [ref]
199
200
: await GitRefManager.listRefs({
200
201
fs,
201
202
gitdir,
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4