-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.d.ts
More file actions
2484 lines (2423 loc) · 91.2 KB
/
Copy pathindex.d.ts
File metadata and controls
2484 lines (2423 loc) · 91.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* auto-generated by NAPI-RS */
/* eslint-disable */
export declare class Blob {
/** Get the id (SHA1) of a repository blob */
id(): string
/** Determine if the blob content is most certainly binary or not. */
isBinary(): boolean
/** Get the content of this blob. */
content(): Buffer
/** Get the size in bytes of the contents of this blob. */
size(): number
}
/**
* A git branch.
*
* A branch is a thin wrapper around an underlying reference; the full
* reference name is available via `reference_name`.
*/
export declare class Branch {
/**
* Return the name of the given local or remote branch.
*
* Returns `None` if the name is not valid utf-8.
*/
name(): string | null
/** Determine if the current local branch is pointed at by HEAD. */
isHead(): boolean
/**
* Get the full name of the reference backing this branch
* (e.g. `refs/heads/main`).
*
* Returns `None` if the reference name is not valid utf-8.
*/
referenceName(): string | null
/** Delete an existing branch reference. */
delete(): void
/**
* Return the reference supporting the remote tracking branch, given a local
* branch reference.
*
* Returns `None` when the branch has no configured upstream.
*/
upstream(): Branch | null
/**
* Return the reference backing this branch as a live `Reference`.
*
* Branches are direct references, so the resolved direct reference is
* returned (e.g. `refs/heads/main`).
*/
get(): Reference
}
export declare class Commit {
/** Get the id (SHA1) of a repository object */
id(): string
/**
* Get the id of the tree pointed to by this commit.
*
* No attempts are made to fetch an object from the ODB.
*/
treeId(): string
/** Get the tree pointed to by this commit. */
tree(): Tree
/**
* Get the full message of a commit.
*
* The returned message will be slightly prettified by removing any
* potential leading newlines.
*
* `None` will be returned if the message is not valid utf-8
*/
message(): string | null
/**
* Get the full message of a commit as a byte slice.
*
* The returned message will be slightly prettified by removing any
* potential leading newlines.
*/
messageBytes(): Buffer
/**
* Get the encoding for the message of a commit, as a string representing a
* standard encoding name.
*
* `None` will be returned if the encoding is not known
*/
messageEncoding(): string | null
/**
* Get the full raw message of a commit.
*
* `None` will be returned if the message is not valid utf-8
*/
messageRaw(): string | null
/** Get the full raw message of a commit. */
messageRawBytes(): Buffer
/**
* Get the full raw text of the commit header.
*
* `None` will be returned if the message is not valid utf-8
*/
rawHeader(): string | null
/** Get an arbitrary header field. */
headerFieldBytes(field: string): Buffer
/** Get the full raw text of the commit header. */
rawHeaderBytes(): Buffer
/**
* Get the short "summary" of the git commit message.
*
* The returned message is the summary of the commit, comprising the first
* paragraph of the message with whitespace trimmed and squashed.
*
* `None` may be returned if an error occurs or if the summary is not valid
* utf-8.
*/
summary(): string | null
/**
* Get the short "summary" of the git commit message.
*
* The returned message is the summary of the commit, comprising the first
* paragraph of the message with whitespace trimmed and squashed.
*
* `None` may be returned if an error occurs
*/
summaryBytes(): Buffer | null
/**
* Get the long "body" of the git commit message.
*
* The returned message is the body of the commit, comprising everything
* but the first paragraph of the message. Leading and trailing whitespaces
* are trimmed.
*
* `None` may be returned if an error occurs or if the summary is not valid
* utf-8.
*/
body(): string | null
/**
* Get the long "body" of the git commit message.
*
* The returned message is the body of the commit, comprising everything
* but the first paragraph of the message. Leading and trailing whitespaces
* are trimmed.
*
* `None` may be returned if an error occurs.
*/
bodyBytes(): Buffer | null
/**
* Get the commit time (i.e. committer time) of a commit.
*
* Returns the committer time as a UTC `Date`; the committer's timezone
* offset is not preserved (the value is normalized to UTC).
*/
time(): Date
/** Get the author of this commit. */
author(): Signature
/** Get the committer of this commit. */
committer(): Signature
/**
* Amend this existing commit with all non-`None` values
*
* This creates a new commit that is exactly the same as the old commit,
* except that any non-`None` values will be updated. The new commit has
* the same parents as the old commit.
*
* For information about `update_ref`, see [`Repository::commit`].
*
* [`Repository::commit`]: struct.Repository.html#method.commit
*/
amend(updateRef?: string | undefined | null, author?: Signature | undefined | null, committer?: Signature | undefined | null, messageEncoding?: string | undefined | null, message?: string | undefined | null, tree?: Tree | undefined | null): string
/**
* Get the number of parents of this commit.
*
* Use the `parents` iterator to return an iterator over all parents.
*/
parentCount(): number
/**
* Get the specified parent of the commit.
*
* Use the `parents` iterator to return an iterator over all parents.
*/
parent(i: number): Commit
/**
* Get the specified parent id of the commit.
*
* This is different from `parent`, which will attempt to load the
* parent commit from the ODB.
*
* Use the `parent_ids` iterator to return an iterator over all parents.
*/
parentId(i: number): string
/** Casts this Commit to be usable as an `Object` */
asObject(): GitObject
}
/**
* A git configuration store.
*
* Obtain one with `Repository.config()` (a prioritized view of system, global
* and repository config) or `Config.openDefault()` (system/global/XDG only).
*/
export declare class Config {
/**
* Open the global, XDG and system configuration files into a single
* prioritized config object that can be used when accessing default config
* data outside a repository.
*/
static openDefault(): Config
/**
* Get the value of a string config variable as an owned string.
*
* All config files are searched in order of their level (highest priority
* first) and the first occurrence is returned. Errors if the value is not
* valid utf-8 or the key is missing.
*/
getString(name: string): string
/** Get the value of a boolean config variable. */
getBoolean(name: string): boolean
/**
* Get the value of an integer config variable, as a JS `number`.
*
* Reads the value as a 64-bit integer. Errors with `InvalidArg` when it lies
* outside the JS safe-integer range (±(2^53 − 1)), where a `number` would lose
* precision — use `getBigInt` for those.
*/
getNumber(name: string): number
/**
* Get the value of an i64 config variable, as a JS `bigint`.
*
* Returns a `bigint` rather than a `number` so values beyond
* `Number.MAX_SAFE_INTEGER` (2^53 - 1) survive without truncation.
*/
getBigInt(name: string): bigint
/**
* Set the value of a string config variable in the config file with the
* highest level (usually the local one).
*/
setString(name: string, value: string): void
/**
* Set the value of a boolean config variable in the config file with the
* highest level (usually the local one).
*/
setBoolean(name: string, value: boolean): void
/**
* Set the value of an integer config variable in the config file with the
* highest level (usually the local one). Takes a JS `number`.
*
* Errors with `InvalidArg` when `value` is not an integer or lies outside the
* JS safe-integer range (±(2^53 − 1)) — use `setBigInt` for larger magnitudes
* rather than silently truncating.
*/
setNumber(name: string, value: number): void
/**
* Set the value of an i64 config variable in the config file with the
* highest level (usually the local one). Takes a JS `bigint`.
*
* Errors with `InvalidArg` if the `bigint` does not fit losslessly in an
* i64 rather than silently truncating it.
*/
setBigInt(name: string, value: bigint): void
/**
* Delete a config variable from the config file with the highest level
* (usually the local one).
*/
removeEntry(name: string): void
/**
* Create a read-only point-in-time snapshot of this configuration.
*
* A snapshot gives a consistent view for looking up complex values. Note
* that `get_*` on a live (non-snapshot) config re-reads the underlying
* files on each call.
*/
snapshot(): Config
/**
* List configuration entries, optionally filtered by a glob pattern.
*
* Each borrowed entry is eagerly materialized into an owned `ConfigEntry`.
* Entries whose name or value is not valid utf-8 are skipped.
*/
entries(glob?: string | undefined | null): Array<ConfigEntry>
}
export declare class Cred {
/**
* Create a "default" credential usable for Negotiate mechanisms like NTLM
* or Kerberos authentication.
*/
constructor()
/**
* Create a new ssh key credential object used for querying an ssh-agent.
*
* The username specified is the username to authenticate.
*/
static sshKeyFromAgent(username: string): Cred
/** Create a new passphrase-protected ssh key credential object. */
static sshKey(username: string, publickey: string | undefined | null, privatekey: string, passphrase?: string | undefined | null): Cred
/** Create a new ssh key credential object reading the keys from memory. */
static sshKeyFromMemory(username: string, publickey: string | undefined | null, privatekey: string, passphrase?: string | undefined | null): Cred
/** Create a new plain-text username and password credential object. */
static userpassPlaintext(username: string, password: string): Cred
/**
* Create a credential to specify a username.
*
* This is used with ssh authentication to query for the username if none is
* specified in the URL.
*/
static username(username: string): Cred
/** Check whether a credential object contains username information. */
hasUsername(): boolean
/**
* Return the type of credentials that this object represents.
*
* The value is the raw `CredentialType` bitset (an OR-able `number`); test
* individual bits with `credTypeContains` and the `CredentialType` constants.
*/
credType(): number
}
/**
* An iterator over the diffs in a delta
*
* This type extends JavaScript's `Iterator`, and so has the iterator helper
* methods. It may extend the upcoming TypeScript `Iterator` class in the future.
*
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator#iterator_helper_methods
* @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-6.html#iterator-helper-methods
*/
export declare class Deltas extends Iterator<DiffDelta, void, void> {
next(value?: void): IteratorResult<DiffDelta, void>
}
export declare class Diff {
/**
* Merge one diff into another.
*
* This merges items from the "from" list into the "self" list. The
* resulting diff will have all items that appear in either list.
* If an item appears in both lists, then it will be "merged" to appear
* as if the old version was from the "onto" list and the new version
* is from the "from" list (with the exception that if the item has a
* pending DELETE in the middle, then it will show as deleted).
*/
merge(diff: Diff): void
/** Returns an iterator over the deltas in this diff. */
deltas(): Deltas
/** Check if deltas are sorted case sensitively or insensitively. */
isSortedIcase(): boolean
}
export declare class DiffDelta {
/**
* Returns the flags on the delta.
*
* The value is the raw `git2::DiffFlags` bitset (an OR-able `number`); test
* individual bits with `diffFlagsContains` and the `DiffFlags` constants.
*/
flags(): number
/** Returns the number of files in this delta. */
numFiles(): number
/** Returns the status of this entry */
status(): Delta
/**
* Return the file which represents the "from" side of the diff.
*
* What side this means depends on the function that was used to generate
* the diff and will be documented on the function itself.
*/
oldFile(): DiffFile
/**
* Return the file which represents the "to" side of the diff.
*
* What side this means depends on the function that was used to generate
* the diff and will be documented on the function itself.
*/
newFile(): DiffFile
}
export declare class DiffFile {
/**
* Returns the Oid of this item.
*
* If this entry represents an absent side of a diff (e.g. the `old_file`
* of a `Added` delta), then the oid returned will be zeroes.
*/
id(): string
/**
* Returns the path of the entry relative to the working directory of the
* repository, as a lossily-decoded (UTF-8) string.
*
* Returns `null` when the path is absent or not representable.
*/
path(): string | null
/** Returns the size of this entry, in bytes */
size(): number
/** Returns `true` if file(s) are treated as binary data. */
isBinary(): boolean
/** Returns `true` if file(s) are treated as text data. */
isNotBinary(): boolean
/** Returns `true` if `id` value is known correct. */
isValidId(): boolean
/** Returns `true` if file exists at this side of the delta. */
exists(): boolean
/** Returns file mode. */
mode(): FileMode
}
/**
* @remarks Single-use: consumed by the first `fetch()` or `fetchAsync()` call.
* Reusing the same instance throws (`InvalidArg`, "FetchOptions can only be used
* once") — synchronously at the call site even for `fetchAsync` (it does NOT
* reject the returned Promise). Construct a fresh instance per call.
*/
export declare class FetchOptions {
constructor()
/** Set the callbacks to use for the fetch operation. */
remoteCallback(callback: RemoteCallbacks): this
/** Set the proxy options to use for the fetch operation. */
proxyOptions(options: ProxyOptions): this
/** Set whether to perform a prune after the fetch. */
prune(prune: FetchPrune): this
/**
* Set whether to write the results to FETCH_HEAD.
*
* Defaults to `true`.
*/
updateFetchhead(update: boolean): this
/**
* Set fetch depth, a value less or equal to 0 is interpreted as pull
* everything (effectively the same as not declaring a limit depth).
*/
depth(depth: number): this
/**
* Set how to behave regarding tags on the remote, such as auto-downloading
* tags for objects we're downloading or downloading all of them.
*
* The default is to auto-follow tags.
*/
downloadTags(opt: AutotagOption): this
/**
* Set remote redirection settings; whether redirects to another host are
* permitted.
*
* By default, git will follow a redirect on the initial request
* (`/info/refs`), but not subsequent requests.
*/
followRedirects(opt: RemoteRedirect): this
/**
* Set extra headers for this fetch operation.
*
* Throws if any header contains an interior NUL byte.
*/
customHeaders(headers: Array<string>): this
}
export declare class GitObject {
/** Get the id (SHA1) of a repository object */
id(): string
/** Get the type of the object. */
kind(): ObjectType | null
/**
* Recursively peel an object until an object of the specified type is met.
*
* If you pass `Any` as the target type, then the object will be
* peeled until the type changes (e.g. a tag will be chased until the
* referenced object is no longer a tag).
*/
peel(kind: ObjectType): GitObject
/** Recursively peel an object until a blob is found */
peelToBlob(): Blob
}
/**
* A git index (the staging area).
*
* Obtain one with `Repository.index()`. Mutating methods change the in-memory
* index only; call `write()` to persist it to disk, or `writeTree()` to write
* its current state to the object database as a tree (whose OID can then be
* used to create a commit).
*/
export declare class Index {
/**
* Add or update an index entry from a file on disk.
*
* The `path` is relative to the repository's working directory and must be
* readable. This forces the file to be added to the index even if it is
* ignored.
*/
addPath(path: string): void
/**
* Add or update index entries matching files in the working directory.
*
* `pathspecs` defaults to `["*"]` (everything) when omitted. Ignored files
* are skipped unless `force` is `true`, which maps to
* `IndexAddOption::FORCE`.
*/
addAll(pathspecs?: Array<string> | undefined | null, force?: boolean | undefined | null): void
/**
* Update all index entries to match the working directory.
*
* Existing entries are refreshed and entries whose file no longer exists are
* removed. `pathspecs` defaults to `["*"]` when omitted. This will fail on a
* bare index.
*/
updateAll(pathspecs?: Array<string> | undefined | null): void
/** Remove an index entry corresponding to a file on disk. */
removePath(path: string): void
/** Get the count of entries currently in the index. */
size(): number
/** Write the in-memory index back to disk using an atomic file lock. */
write(): void
/**
* Write the index as a tree to the object database and return its OID.
*
* The index must be associated with an existing repository and must not
* contain any conflicted entries. The returned OID can be used to create a
* commit.
*/
writeTree(): string
}
export declare class ProxyOptions {
constructor()
/**
* Try to auto-detect the proxy from the git configuration.
*
* Note that this will override `url` specified before.
*/
auto(): this
/**
* Specify the exact URL of the proxy to use.
*
* Note that this will override `auto` specified before.
*/
url(url: string): this
}
/**
* @remarks Single-use: consumed by the first `push()` or `pushAsync()` call.
* Reusing the same instance throws (`InvalidArg`, "PushOptions can only be used
* once") — synchronously at the call site even for `pushAsync` (it does NOT
* reject the returned Promise). Construct a fresh instance per call.
*/
export declare class PushOptions {
constructor()
/** Set the callbacks to use for the push operation. */
remoteCallback(callback: RemoteCallbacks): this
/** Set the proxy options to use for the push operation. */
proxyOptions(options: ProxyOptions): this
/**
* If the transport being used to push to the remote requires the creation
* of a pack file, this controls the number of worker threads used by the
* packbuilder when creating that pack file to be sent to the remote.
*
* If set to 0 the packbuilder will auto-detect the number of threads to
* create, and the default value is 1.
*/
packbuilderParallelism(parallel: number): this
/**
* Set remote redirection settings; whether redirects to another host are
* permitted.
*
* By default, git will follow a redirect on the initial request
* (`/info/refs`), but not subsequent requests.
*/
followRedirects(opt: RemoteRedirect): this
/**
* Set extra headers for this push operation.
*
* Throws if any header contains an interior NUL byte.
*/
customHeaders(headers: Array<string>): this
/**
* Set "push options" to deliver to the remote.
*
* Throws if any push option contains an interior NUL byte.
*/
remotePushOptions(options: Array<string>): this
}
export declare class Reference {
/**
* Ensure the reference name is well-formed.
*
* Validation is performed as if [`ReferenceFormat::ALLOW_ONELEVEL`]
* was given to [`Reference.normalize_name`]. No normalization is
* performed, however.
*
* ```ts
* import { Reference } from '@napi-rs/simple-git'
*
* console.assert(Reference.isValidName("HEAD"));
* console.assert(Reference.isValidName("refs/heads/main"));
*
* // But:
* console.assert(!Reference.isValidName("main"));
* console.assert(!Reference.isValidName("refs/heads/*"));
* console.assert(!Reference.isValidName("foo//bar"));
* ```
*/
static isValidName(name: string): boolean
/** Check if a reference is a local branch. */
isBranch(): boolean
/** Check if a reference is a note. */
isNote(): boolean
/** Check if a reference is a remote tracking branch */
isRemote(): boolean
/** Check if a reference is a tag */
isTag(): boolean
kind(): ReferenceType
/**
* Get the full name of a reference.
*
* Returns `None` if the name is not valid utf-8.
*/
name(): string | null
/**
* Get the full shorthand of a reference.
*
* This will transform the reference name into a name "human-readable"
* version. If no shortname is appropriate, it will return the full name.
*
* Returns `None` if the shorthand is not valid utf-8.
*/
shorthand(): string | null
/**
* Get the OID pointed to by a direct reference.
*
* Only available if the reference is direct (i.e. an object id reference,
* not a symbolic one).
*/
target(): string | null
/**
* Return the peeled OID target of this reference.
*
* This peeled OID only applies to direct references that point to a hard
* Tag object: it is the result of peeling such Tag.
*/
targetPeel(): string | null
/**
* Peel a reference to a tree
*
* This method recursively peels the reference until it reaches
* a tree.
*/
peelToTree(): Tree
/**
* Get full name to the reference pointed to by a symbolic reference.
*
* May return `None` if the reference is either not symbolic or not a
* valid utf-8 string.
*/
symbolicTarget(): string | null
/**
* Resolve a symbolic reference to a direct reference.
*
* This method iteratively peels a symbolic reference until it resolves to
* a direct reference to an OID.
*
* If a direct reference is passed as an argument, a copy of that
* reference is returned.
*/
resolve(): Reference
/**
* Rename an existing reference.
*
* This method works for both direct and symbolic references.
*
* If the force flag is not enabled, and there's already a reference with
* the given name, the renaming will fail.
*/
rename(newName: string, force: boolean, msg: string): Reference
}
export declare class Remote {
/** Ensure the remote name is well-formed. */
static isValidName(name: string): boolean
/**
* Get the remote's name.
*
* Returns `None` if this remote has not yet been named or if the name is
* not valid utf-8
*/
name(): string | null
/**
* Get the remote's url.
*
* Returns `None` if the url is not valid utf-8
*/
url(): string | null
/**
* Get the remote's pushurl.
*
* Returns `None` if the pushurl is not valid utf-8
*/
pushUrl(): string | null
/**
* Get the remote's default branch.
*
* The remote (or more exactly its transport) must have connected to the
* remote repository. This default branch is available as soon as the
* connection to the remote is initiated and it remains available after
* disconnecting.
*/
defaultBranch(): string
/** Open a connection to a remote. */
connect(dir: Direction): void
/** Check whether the remote is connected */
connected(): boolean
/** Disconnect from the remote */
disconnect(): void
/**
* Cancel the operation
*
* At certain points in its operation, the network code checks whether the
* operation has been cancelled and if so stops the operation.
*/
stop(): void
/**
* Download new data and update tips
*
* Convenience function to connect to a remote, download the data,
* disconnect and update the remote-tracking branches.
*/
fetch(refspecs: Array<string>, fetchOptions?: FetchOptions | undefined | null): void
/**
* Perform a push.
*
* If `refspecs` is empty the configured push refspecs are used. Delete a
* remote ref by pushing `":refs/heads/branch"`. To detect per-ref server
* rejections, set a `pushUpdateReference` callback on the `RemoteCallbacks`.
*/
push(refspecs: Array<string>, pushOptions?: PushOptions | undefined | null): void
/**
* Asynchronous variant of `fetch`, performed off the main thread.
*
* `fetchOptions` may carry data-only settings (depth, prune, proxy url,
* headers, ...). It must NOT carry `RemoteCallbacks`: those hold JS-backed
* callbacks bound to the main JS thread and cannot be invoked safely from a
* worker thread. If callbacks are required, use the synchronous `fetch`.
*
* Resolves the remote by name against the repository's CURRENT on-disk
* configuration at the moment this async operation actually runs, not
* against a snapshot of the `Remote` object's state when it was loaded.
* If `remoteSetUrl`/`remoteAddFetch`/`remoteDelete` mutate this remote's
* config after it was loaded but before this call completes, the
* mutation IS observed here — unlike the synchronous `fetch()`, which
* operates on the already-loaded snapshot and is documented as
* unaffected by later config changes. Use the synchronous `fetch()`
* when strict snapshot isolation from concurrent config changes matters.
*
* Safety: do not use the same `Remote` from the main thread while this async
* operation is pending; the underlying git2 handle is not `Sync`.
*
* Synchronous pre-throw: although the declared return is `Promise<void>`,
* argument/state validation runs synchronously on the calling thread and
* THROWS synchronously (the CALL throws — it does NOT return a rejected
* Promise) when `fetchOptions` has already been consumed by a prior async
* call or carries `RemoteCallbacks`. Wrap the CALL itself
* (`try { await remote.fetchAsync(...) }`), not just the awaited Promise.
*/
fetchAsync(refspecs: Array<string>, fetchOptions?: FetchOptions | undefined | null, signal?: AbortSignal | undefined | null): Promise<void>
/**
* Asynchronous variant of `push`, performed off the main thread.
*
* `pushOptions` may carry data-only settings (packbuilder parallelism,
* proxy url, headers, ...). It must NOT carry `RemoteCallbacks`: those hold
* JS-backed callbacks bound to the main JS thread and cannot be invoked
* safely from a worker thread. If callbacks (e.g. `pushUpdateReference`) are
* required, use the synchronous `push`.
*
* Resolves against a URL/refspec snapshot captured from this loaded
* `Remote` at call time (using the configured `pushurl` when set, else
* `url`), rather than re-resolving the remote by name against live
* on-disk config the way `fetchAsync` does. This asymmetry with
* `fetchAsync` is intentional and is not merely a config-drift
* optimization: libgit2's local transport ignores a configured `pushurl`
* for the actual push — it re-derives the destination directly from the
* remote's fetch `url` (see `transports/local.c`'s `local_push()`,
* `push->remote->url`), even though `pushurl` is correctly used during
* the connection handshake (`remote.c`'s `git_remote__urlfordirection`).
* Re-resolving by name here, like `fetchAsync` does, would silently push
* to the wrong destination for any local/file-path remote with a
* configured `pushurl`. Capturing the effective push URL up front and
* handing it to an anonymous remote sidesteps the bug, because that
* remote's SOLE url is already the pushurl-resolved value. Trade-off: a
* later `remoteSetUrl`/`remoteSetPushUrl`/`remoteAddPush` on the same name
* after this `Remote` was loaded is NOT observed by an already-scheduled
* `pushAsync`, matching the synchronous `push()` contract ("no loaded
* remote instances will be affected"). Also note: pushurl + refspecs are
* the config properties this snapshot captures, not the complete set that
* can diverge between named and anonymous remote resolution — libgit2's
* HTTP proxy auto-detection also consults `remote.<name>.proxy`, so
* `pushAsync(...)` combined with `PushOptions.proxyOptions(new
* ProxyOptions().auto())` will not pick up that per-remote proxy config
* the way the synchronous, named-remote `push()` does. This is a known,
* accepted gap (see the `remote_url` field doc on `RemotePushTask`), not
* chased further here.
*
* Safety: do not use the same `Remote` from the main thread while this async
* operation is pending; the underlying git2 handle is not `Sync`.
*
* Synchronous pre-throw: although the declared return is `Promise<void>`,
* argument/state validation runs synchronously on the calling thread and
* THROWS synchronously (the CALL throws — it does NOT return a rejected
* Promise) when `pushOptions` has already been consumed by a prior async
* call or carries `RemoteCallbacks`, or when this remote's push URL is
* unreadable/absent or its configured push refspecs cannot be read. Wrap the
* CALL itself (`try { await remote.pushAsync(...) }`), not just the awaited
* Promise.
*/
pushAsync(refspecs: Array<string>, pushOptions?: PushOptions | undefined | null, signal?: AbortSignal | undefined | null): Promise<void>
/**
* Update the tips to the new state
*
* `update_flags` is a raw bitset of `RemoteUpdateFlags` OR-ed together
* (e.g. `RemoteUpdateFlags.UpdateFetchHead`). Unknown bits are ignored.
*/
updateTips(updateFlags: number, downloadTags: AutotagOption, callbacks?: RemoteCallbacks | undefined | null, msg?: string | undefined | null): void
}
/**
* @remarks Single-use: attaching this to a `FetchOptions`/`PushOptions` via
* `remoteCallback()` consumes it; a second attach throws (`InvalidArg`,
* "RemoteCallbacks can only be used once"). Construct a fresh instance per
* attach. (`updateTips` does NOT consume it and may reuse the same instance.)
*/
export declare class RemoteCallbacks {
constructor()
/**
* The callback through which to fetch credentials if required.
*
* # Example
*
* Prepare a callback to authenticate using the `$HOME/.ssh/id_rsa` SSH key, and
* extracting the username from the URL (i.e. git@github.com:rust-lang/git2-rs.git):
*
* ```js
* import { join } from 'node:path'
* import { homedir } from 'node:os'
*
* import { Cred, FetchOptions, RemoteCallbacks, RepoBuilder, credTypeContains } from '@napi-rs/simple-git'
*
* const builder = new RepoBuilder()
*
* const remoteCallbacks = new RemoteCallbacks()
* .credentials((cred) => {
* return Cred.sshKey(cred.username, null, join(homedir(), '.ssh', 'id_rsa'), null)
* })
*
* const fetchOptions = new FetchOptions().depth(0).remoteCallback(remoteCallbacks)
*
* const repo = builder.branch('master')
* .fetchOptions(fetchOptions)
* .clone("git@github.com:rust-lang/git2-rs.git", "git2-rs")
* ```
*/
credentials(callback: (arg: CredInfo) => Cred): this
/** The callback through which progress is monitored. */
transferProgress(callback: (arg: Progress) => void): this
/**
* The callback through which progress of push transfer is monitored.
*
* The callback receives a single `PushTransferProgress` object describing how
* many objects have been processed and how many bytes have been sent.
*/
pushTransferProgress(callback: (arg: PushTransferProgress) => void): this
/**
* Set a callback to get invoked for each updated reference on a push.
*
* The callback is invoked once per reference with a single
* `PushUpdateReference` object. `status` is `null` when the reference was
* updated successfully; otherwise it is the server's rejection reason.
*/
pushUpdateReference(callback: (arg: PushUpdateReference) => void): this
}
export declare class RepoBuilder {
constructor()
/**
* Indicate whether the repository will be cloned as a bare repository or
* not.
*/
bare(bare: boolean): this
/**
* Specify the name of the branch to check out after the clone.
*
* If not specified, the remote's default branch will be used.
*/
branch(branch: string): this
/**
* Configures options for bypassing the git-aware transport on clone.
*
* Bypassing it means that instead of a fetch libgit2 will copy the object
* database directory instead of figuring out what it needs, which is
* faster. If possible, it will hardlink the files to save space.
*/
cloneLocal(cloneLocal: CloneLocal): this
/**
* Options which control the fetch, including callbacks.
*
* The callbacks are used for reporting fetch progress, and for acquiring
* credentials in the event they are needed.
*/
fetchOptions(fetchOptions: FetchOptions): this
clone(url: string, path: string): Repository
}
export declare class Repository {
/**
* Eagerly release the underlying git2 repository handle
* (`git_repository_free`), closing any open packfile file descriptors and
* memory-mapped indexes without waiting for JavaScript garbage collection.
*
* This is idempotent: calling it more than once (or calling `free()`
* afterwards) is a no-op.
*
* After disposal, every throwing method throws
* `"Repository has been disposed"`; the `Option`-returning methods
* (`workdir()`, `namespace()`, `findRemote()`, `findTree()`,
* `findCommit()`, `findTag()`, `findTagByPrefix()`) return `null` instead.
* Any handle previously derived from
* this repository — `Remote`, `Reference`, `Tree`, `TreeEntry`, `Commit`,
* `Tag`, `Branch`, `GitObject`, `Diff`, `RevWalk` and their descendants —
* throws the same `"Repository has been disposed"` error on use, whether it
* is the receiver or an argument passed to another method. This is
* machine-enforced (mirroring better-sqlite3's `db.close()`), not merely a
* documented contract.
*
* Disposal does NOT cancel `*Async` operations already in flight: a worker
* scheduled before `dispose()` reopens the repository from its path on its
* own thread and runs to completion (its promise still resolves and refs or
* objects may change on disk), because it never touches this freed handle.
* New `*Async` calls made after disposal throw synchronously. To cancel a
* pending async operation, pass an `AbortSignal` to the `*Async` method
* rather than relying on `dispose()`.
*
* `Symbol.dispose` cannot be generated by napi, so `using` support is
* opt-in via a single line at startup:
*
* ```js
* Repository.prototype[Symbol.dispose] ??= Repository.prototype.dispose
* ```
*/
dispose(): void
/**
* Alias for `dispose()`. Eagerly releases the underlying git2 repository
* handle; idempotent. See `dispose()` for the full disposal contract.
*/
free(): void
static init(p: string): Repository
/**
* Find and open an existing repository, with additional options.
*
* `flags` is a raw bitset of `RepositoryOpenFlags` OR-ed together (e.g.
* `RepositoryOpenFlags.NoSearch | RepositoryOpenFlags.CrossFS`). Unknown
* bits are ignored.
*
* - `RepositoryOpenFlags.NoSearch`: only open the repository at `path`; do
* not walk upward through parent directories searching for one.
* - `RepositoryOpenFlags.CrossFS`: when searching upward, allow crossing
* filesystem boundaries.
* - `RepositoryOpenFlags.Bare`: force opening as a bare repository (ignore
* any working directory) and defer loading its config.
* - `RepositoryOpenFlags.NoDotGit`: don't try appending `/.git` to `path`.
* - `RepositoryOpenFlags.FromEnv`: resolve the repository from the same
* environment variables git honors (ignores the other flags and
* `ceilingDirs`).
*
* Note: a `FromEnv` handle re-consults the environment when an `*Async`
* method reopens it on a worker thread. The git directory, working
* directory, and namespace are re-pinned to this handle's resolved
* values, but environment-derived index/object inputs (notably
* `GIT_INDEX_FILE`, `GIT_OBJECT_DIRECTORY`, and
* `GIT_ALTERNATE_OBJECT_DIRECTORIES`) are re-read from the *current*
* process environment at reopen time. Mutating those variables between a
* synchronous call and a later `*Async` call on the same handle can make
* the two observe different index/object state. For stable results, do
* not change those variables mid-flight, or open without `FromEnv`.
*
* `ceilingDirs` is a list of absolute paths at which the upward search stops
* (ignored when `RepositoryOpenFlags.FromEnv` is set).
*/
static openExt(path: string, flags: number, ceilingDirs: Array<string>): Repository
/**
* Attempt to open an already-existing repository at or above `path`
*
* This starts at `path` and looks up the filesystem hierarchy
* until it finds a repository.
*/
static discover(path: string): Repository
/**
* Creates a new `--bare` repository in the specified folder.
*
* The folder must exist prior to invoking this function.
*/
static initBare(path: string): Repository
/**
* Clone a remote repository.
*
* See the `RepoBuilder` struct for more information. This function will
* delegate to a fresh `RepoBuilder`