diff --git a/CHANGELOG.md b/CHANGELOG.md index 57d0616de8..c0576befb8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Change Log +## Unreleased + +- Ship maintained TypeScript declarations with `@readme/nodegit`, including + `Repository.free()` and corrections for repository, remote callback, progress, + and libgit2 option APIs. + ## v0.28.0-alpha.35 [(2025-06-03)](https://github.com/nodegit/nodegit/releases/tag/v0.28.0-alpha.35) [Full Changelog](https://github.com/nodegit/nodegit/compare/v0.28.0-alpha.34...v0.28.0-alpha.35) diff --git a/README.md b/README.md index f5928c9ceb..0ac8d78d83 100644 --- a/README.md +++ b/README.md @@ -35,9 +35,12 @@ NodeGit will work on most systems out-of-the-box without any native dependencies. ```bash -npm install nodegit +npm install @readme/nodegit ``` +TypeScript declarations ship with `@readme/nodegit`. Import from that package and +remove `@types/nodegit` and any `tsconfig` path mapping to its declarations. + In Ubuntu: ```sh @@ -85,7 +88,7 @@ instructions. ### Cloning a repository and reading a file: ```javascript -var Git = require("nodegit"); +var Git = require("@readme/nodegit"); // Clone a given repository into the `./tmp` folder. Git.Clone("https://github.com/nodegit/nodegit", "./tmp") @@ -125,7 +128,7 @@ Git.Clone("https://github.com/nodegit/nodegit", "./tmp") ### Emulating git log: ```javascript -var Git = require("nodegit"); +var Git = require("@readme/nodegit"); // Open the repository directory. Git.Repository.open("tmp") diff --git a/generate/input/descriptor.json b/generate/input/descriptor.json index 99837534db..9ac191569d 100644 --- a/generate/input/descriptor.json +++ b/generate/input/descriptor.json @@ -3746,7 +3746,7 @@ } }, "git_repository_free": { - "ignore": true + "ignore": false }, "git_repository_hashfile": { "ignore": true diff --git a/generate/input/libgit2-supplement.json b/generate/input/libgit2-supplement.json index 742216f030..82a02056e4 100644 --- a/generate/input/libgit2-supplement.json +++ b/generate/input/libgit2-supplement.json @@ -1210,6 +1210,10 @@ "isErrorCode": true } }, + "git_repository_free": { + "isManual": true, + "cFile": "generate/templates/manual/repository/free.cc" + }, "git_repository__cleanup": { "type": "function", "file": "sys/repository.h", diff --git a/generate/templates/manual/commit/extract_signature.cc b/generate/templates/manual/commit/extract_signature.cc index 82a2141116..1f8ee37a9d 100644 --- a/generate/templates/manual/commit/extract_signature.cc +++ b/generate/templates/manual/commit/extract_signature.cc @@ -3,6 +3,7 @@ NAN_METHOD(GitCommit::ExtractSignature) if (info.Length() == 0 || !info[0]->IsObject()) { return Nan::ThrowError("Repository repo is required."); } + if (Nan::ObjectWrap::Unwrap(info[0].As())->GetValue() == NULL) return Nan::ThrowError("Repository has been freed."); if (info.Length() == 1 || (!info[1]->IsObject() && !info[1]->IsString())) { return Nan::ThrowError("Oid commit_id is required."); diff --git a/generate/templates/manual/filter_list/load.cc b/generate/templates/manual/filter_list/load.cc index 22e2f1f4f3..309a95539f 100644 --- a/generate/templates/manual/filter_list/load.cc +++ b/generate/templates/manual/filter_list/load.cc @@ -22,6 +22,7 @@ NAN_METHOD(GitFilterList::Load) { if (info.Length() == 0 || !info[0]->IsObject()) { return Nan::ThrowError("Repository repo is required."); } + if (Nan::ObjectWrap::Unwrap(info[0].As())->GetValue() == NULL) return Nan::ThrowError("Repository has been freed."); if (info.Length() == 2 || !info[2]->IsString()) { return Nan::ThrowError("String path is required."); diff --git a/generate/templates/manual/include/async_worker.h b/generate/templates/manual/include/async_worker.h index b8f2909901..c8a0bb2bf9 100644 --- a/generate/templates/manual/include/async_worker.h +++ b/generate/templates/manual/include/async_worker.h @@ -7,6 +7,7 @@ #include #include "lock_master.h" #include "cleanup_handle.h" +#include "tracker_wrap.h" namespace nodegit { class AsyncWorker : public Nan::AsyncWorker { @@ -47,8 +48,10 @@ namespace nodegit { } auto objectWrapPointer = Nan::ObjectWrap::Unwrap(item.As()); + auto release = RetainNativeOwner(objectWrapPointer); objectWrapPointer->Reference(); - RegisterCleanupCall([objectWrapPointer]() { + RegisterCleanupCall([objectWrapPointer, release]() { + if (release) release(); objectWrapPointer->Unreference(); }); } @@ -81,6 +84,8 @@ namespace nodegit { std::map> cleanupHandles; Nan::Global callbackErrorHandle; + static std::function RetainNativeOwner(nodegit::TrackerWrap *item) { return item->RetainNativeOwner(); } + static std::function RetainNativeOwner(Nan::ObjectWrap *) { return {}; } private: std::vector> cleanupCalls; bool isCancelled = false; diff --git a/generate/templates/manual/include/nodegit_wrapper.h b/generate/templates/manual/include/nodegit_wrapper.h index c72f29027d..ed46696c38 100644 --- a/generate/templates/manual/include/nodegit_wrapper.h +++ b/generate/templates/manual/include/nodegit_wrapper.h @@ -45,6 +45,11 @@ class NodeGitWrapper : public nodegit::TrackerWrap { protected: cType *raw; std::vector> childCleanupVector; + std::vector> nativeOwnerReleases; + // Explicit free clears raw, but queued results can inherit a still-pinned native owner. + // Clear this pointer with the last pin so a disposed wrapper cannot resurrect freed memory. + cType *retainedRaw = NULL; + size_t nativeRetainCount = 0; // owner of the object, in the memory management sense. only populated // when using ownedByThis, and the type doesn't have a dupFunction @@ -80,11 +85,13 @@ class NodeGitWrapper : public nodegit::TrackerWrap { void Reference(); void Unreference(); + std::function RetainNativeOwner() override; void AddReferenceCallbacks(size_t, std::function, std::function); cType *GetValue(); void ClearValue(); + void ReleaseValue(); private: std::unordered_map> referenceCallbacks; diff --git a/generate/templates/manual/include/tracker_wrap.h b/generate/templates/manual/include/tracker_wrap.h index 3b15eba424..8e44f977f7 100644 --- a/generate/templates/manual/include/tracker_wrap.h +++ b/generate/templates/manual/include/tracker_wrap.h @@ -2,6 +2,7 @@ #define TRACKERWRAP_H #include +#include #include #include @@ -15,6 +16,7 @@ namespace nodegit { public: TrackerWrap() = default; virtual ~TrackerWrap() = default; + virtual std::function RetainNativeOwner() { return {}; } TrackerWrap(const TrackerWrap &other) = delete; TrackerWrap(TrackerWrap &&other) = delete; TrackerWrap& operator=(const TrackerWrap &other) = delete; diff --git a/generate/templates/manual/repository/free.cc b/generate/templates/manual/repository/free.cc new file mode 100644 index 0000000000..d3f3e8fff2 --- /dev/null +++ b/generate/templates/manual/repository/free.cc @@ -0,0 +1,6 @@ +NAN_METHOD(GitRepository::Free) { + GitRepository *repository = Nan::ObjectWrap::Unwrap(info.Holder()); + repository->ReleaseValue(); + + info.GetReturnValue().Set(Nan::Undefined()); +} diff --git a/generate/templates/manual/repository/get_references.cc b/generate/templates/manual/repository/get_references.cc index 56bc12ac34..85cdffede0 100644 --- a/generate/templates/manual/repository/get_references.cc +++ b/generate/templates/manual/repository/get_references.cc @@ -1,5 +1,6 @@ NAN_METHOD(GitRepository::GetReferences) { + if (Nan::ObjectWrap::Unwrap(info.Holder())->GetValue() == NULL) return Nan::ThrowError("Repository has been freed."); if (!info[info.Length() - 1]->IsFunction()) { return Nan::ThrowError("Callback is required and must be a Function."); } diff --git a/generate/templates/manual/repository/get_remotes.cc b/generate/templates/manual/repository/get_remotes.cc index a7c316bb0e..68b02a8be5 100644 --- a/generate/templates/manual/repository/get_remotes.cc +++ b/generate/templates/manual/repository/get_remotes.cc @@ -1,5 +1,6 @@ NAN_METHOD(GitRepository::GetRemotes) { + if (Nan::ObjectWrap::Unwrap(info.Holder())->GetValue() == NULL) return Nan::ThrowError("Repository has been freed."); if (!info[info.Length() - 1]->IsFunction()) { return Nan::ThrowError("Callback is required and must be a Function."); } diff --git a/generate/templates/manual/repository/get_submodules.cc b/generate/templates/manual/repository/get_submodules.cc index 069f6bdbc8..483fde30f5 100644 --- a/generate/templates/manual/repository/get_submodules.cc +++ b/generate/templates/manual/repository/get_submodules.cc @@ -1,5 +1,6 @@ NAN_METHOD(GitRepository::GetSubmodules) { + if (Nan::ObjectWrap::Unwrap(info.Holder())->GetValue() == NULL) return Nan::ThrowError("Repository has been freed."); if (!info[info.Length() - 1]->IsFunction()) { return Nan::ThrowError("Callback is required and must be a Function."); } diff --git a/generate/templates/manual/repository/refresh_references.cc b/generate/templates/manual/repository/refresh_references.cc index 5ddaec57fa..1d7e6d68d9 100644 --- a/generate/templates/manual/repository/refresh_references.cc +++ b/generate/templates/manual/repository/refresh_references.cc @@ -389,6 +389,7 @@ class RefreshReferencesData { NAN_METHOD(GitRepository::RefreshReferences) { + if (Nan::ObjectWrap::Unwrap(info.Holder())->GetValue() == NULL) return Nan::ThrowError("Repository has been freed."); v8::Local signatureType; if (info.Length() == 2) { if (!info[0]->IsString()) { diff --git a/generate/templates/manual/repository/statistics.cc b/generate/templates/manual/repository/statistics.cc index f438bb5f8d..9cc2f3987c 100644 --- a/generate/templates/manual/repository/statistics.cc +++ b/generate/templates/manual/repository/statistics.cc @@ -1773,6 +1773,7 @@ v8::Local RepoAnalysis::biggestCheckoutsToJS() const NAN_METHOD(GitRepository::Statistics) { + if (Nan::ObjectWrap::Unwrap(info.Holder())->GetValue() == NULL) return Nan::ThrowError("Repository has been freed."); if (!info[info.Length() - 1]->IsFunction()) { return Nan::ThrowError("Callback is required and must be a Function."); } diff --git a/generate/templates/manual/src/nodegit_wrapper.cc b/generate/templates/manual/src/nodegit_wrapper.cc index a790d7bc3c..ea764422b1 100644 --- a/generate/templates/manual/src/nodegit_wrapper.cc +++ b/generate/templates/manual/src/nodegit_wrapper.cc @@ -22,6 +22,10 @@ NodeGitWrapper::NodeGitWrapper(typename Traits::cType *raw, bool selfFre selfFreeing = true; } else { SetNativeOwners(owner); + for (nodegit::TrackerWrap *nativeOwner : *GetTrackerWrapOwners()) { + auto release = nativeOwner->RetainNativeOwner(); + if (release) nativeOwnerReleases.push_back(std::move(release)); + } this->owner.Reset(owner); this->raw = raw; } @@ -48,14 +52,13 @@ NodeGitWrapper::NodeGitWrapper(const char *error) template NodeGitWrapper::~NodeGitWrapper() { Unlink(); - if (Traits::isFreeable && selfFreeing) { - Traits::free(raw); - SelfFreeingInstanceCount--; - raw = NULL; + if (selfFreeing) { + ReleaseValue(); } - else if (!selfFreeing) { + else { --NonSelfFreeingConstructedCount; } + for (auto &release : nativeOwnerReleases) release(); } template @@ -136,6 +139,15 @@ void NodeGitWrapper::ClearValue() { raw = NULL; } +template +void NodeGitWrapper::ReleaseValue() { + if (Traits::isFreeable && selfFreeing && raw != NULL) { + Traits::free(raw); + SelfFreeingInstanceCount--; + raw = NULL; + } +} + template thread_local int NodeGitWrapper::SelfFreeingInstanceCount; @@ -174,6 +186,20 @@ void NodeGitWrapper::Unreference() { } } +template +std::function NodeGitWrapper::RetainNativeOwner() { + if (!Traits::isSingleton) return {}; + cType *value = raw != NULL ? raw : retainedRaw; + if (value == NULL) return {}; + ReferenceCounter::incrementCountForPointer((void *)value); + retainedRaw = value; + ++nativeRetainCount; + return [this, value]() { + if (--nativeRetainCount == 0) retainedRaw = NULL; + Traits::free(value); + }; +} + template void NodeGitWrapper::AddReferenceCallbacks(size_t fieldIndex, std::function refCb, std::function unrefCb) { referenceCallbacks[fieldIndex] = refCb; diff --git a/generate/templates/manual/src/wrapper.cc b/generate/templates/manual/src/wrapper.cc index 3bad23c7d4..fd1c6dac13 100644 --- a/generate/templates/manual/src/wrapper.cc +++ b/generate/templates/manual/src/wrapper.cc @@ -4,10 +4,8 @@ #include #include #include -#include #include "../include/wrapper.h" -#include "node_buffer.h" using namespace v8; using namespace node; @@ -67,14 +65,12 @@ NAN_METHOD(Wrapper::ToBuffer) { } int len = Nan::To(info[0]).FromJust(); + if (len < 0) { + return Nan::ThrowRangeError("Length must not be negative."); + } - Local bufferConstructor = Local::Cast( - Nan::Get(Nan::GetCurrentContext()->Global(), Nan::New("Buffer").ToLocalChecked()).ToLocalChecked()); - - Local constructorArgs[1] = { Nan::New(len) }; - Local nodeBuffer = Nan::NewInstance(bufferConstructor, 1, constructorArgs).ToLocalChecked(); - - std::memcpy(node::Buffer::Data(nodeBuffer), Nan::ObjectWrap::Unwrap(info.This())->GetValue(), len); + const char *data = static_cast(Nan::ObjectWrap::Unwrap(info.Holder())->GetValue()); + Local nodeBuffer = Nan::CopyBuffer(data, len).ToLocalChecked(); info.GetReturnValue().Set(nodeBuffer); } diff --git a/generate/templates/partials/guard_arguments.cc b/generate/templates/partials/guard_arguments.cc index bcfc332841..4643a18d48 100644 --- a/generate/templates/partials/guard_arguments.cc +++ b/generate/templates/partials/guard_arguments.cc @@ -1,4 +1,19 @@ +{%each args|argsInfo as arg%} + {%if arg.isSelf |and arg.cppClassName == "GitRepository"%} + if (Nan::ObjectWrap::Unwrap(info.Holder())->GetValue() == NULL) { + return Nan::ThrowError("Repository has been freed."); + } + {%endif%} + {%if arg.isJsArg |and arg.cppClassName == "GitRepository"%} + if (info.Length() > {{arg.jsArg}} && info[{{arg.jsArg}}]->IsObject()) { + GitRepository *repository = Nan::ObjectWrap::Unwrap(info[{{arg.jsArg}}].As()); + if (repository == NULL || repository->GetValue() == NULL) { + return Nan::ThrowError("Repository has been freed."); + } + } + {%endif%} +{%endeach%} {%each args|argsInfo as arg%} {%if arg.isJsArg%} {%if not arg.isOptional%} diff --git a/lib/repository.js b/lib/repository.js index 64d566dcdc..5586962d68 100644 --- a/lib/repository.js +++ b/lib/repository.js @@ -1124,7 +1124,10 @@ Repository.prototype.getHeadCommit = function() { .then(function(head) { return repo.getCommit(head); }) - .catch(function() { + .catch(function(error) { + if (error.errno !== NodeGit.Error.CODE.ENOTFOUND) { + throw error; + } return null; }); }; diff --git a/package-lock.json b/package-lock.json index 700162fa66..820c5f2491 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "license": "MIT", "dependencies": { "@axosoft/nan": "npm:nan@^2.28.0", + "@types/node": "^22.20.4", "fs-extra": "^7.0.0", "json5": "^2.1.0", "lodash": "^4.17.14", @@ -27,6 +28,7 @@ "lcov-result-merger": "^3.1.0", "mocha": "^11.4.0", "nyc": "^17.1.0", + "typescript": "^5.9.3", "walk": "^2.3.9" }, "engines": { @@ -35,9 +37,9 @@ }, "node_modules/@axosoft/nan": { "name": "nan", - "version": "2.28.0", - "resolved": "https://registry.npmjs.org/nan/-/nan-2.28.0.tgz", - "integrity": "sha512-fTsDz99OTq2sVePhGdp4qQhggZFtKr64ZNVyVajRKtMOkJxYekplBh577PiJB12v/D3s2E5cGtOI45LWp6rnLQ==", + "version": "2.29.0", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.29.0.tgz", + "integrity": "sha512-GlGk3HIvitbvs+LT3g6XUP1kpirKNvmDFwF/bmo6XNWSb/eYEs/O4bfgIEIXCZ+lIOTS5xNwDvSGMw6FJdAhtA==", "license": "MIT" }, "node_modules/@babel/code-frame": { @@ -691,6 +693,15 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/node": { + "version": "22.20.4", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.20.4.tgz", + "integrity": "sha512-zJRE40jpHtKqE/C4fgHrAKQLJuSpzEnP9ff9Y7YtoR3Wd2pwqzlekDeEuUQXjRd+QCYnVnNwuJYmhdk9XV8gvA==", + "license": "MIT", + "dependencies": { + "undici-types": "~6.21.0" + } + }, "node_modules/abbrev": { "version": "1.0.9", "dev": true, @@ -4967,6 +4978,20 @@ "is-typedarray": "^1.0.0" } }, + "node_modules/typescript": { + "version": "5.9.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", + "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, "node_modules/unc-path-regex": { "version": "0.1.2", "dev": true, @@ -4975,6 +5000,12 @@ "node": ">=0.10.0" } }, + "node_modules/undici-types": { + "version": "6.21.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz", + "integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==", + "license": "MIT" + }, "node_modules/unique-filename": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/unique-filename/-/unique-filename-4.0.0.tgz", diff --git a/package.json b/package.json index 04e7562467..977ca22ab9 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ } ], "main": "lib/nodegit.js", + "types": "types/index.d.ts", "repository": { "type": "git", "url": "git+https://github.com/readmeio/nodegit.git" @@ -43,6 +44,7 @@ }, "dependencies": { "@axosoft/nan": "npm:nan@^2.28.0", + "@types/node": "^22.20.4", "fs-extra": "^7.0.0", "json5": "^2.1.0", "lodash": "^4.17.14", @@ -59,6 +61,7 @@ "lcov-result-merger": "^3.1.0", "mocha": "^11.4.0", "nyc": "^17.1.0", + "typescript": "^5.9.3", "walk": "^2.3.9" }, "scripts": { @@ -79,7 +82,8 @@ "rebuildDebug": "node generate && node-gyp configure --debug build", "recompile": "node-gyp configure build", "recompileDebug": "node-gyp configure --debug build", - "test": "npm run lint && node --expose-gc test", + "test": "npm run lint && npm run typecheck && node --expose-gc test", + "typecheck": "tsc --noEmit --strict --module node16 --moduleResolution node16 --target es2022 test/types/consumer.ts", "xcodeDebug": "node-gyp configure -- -f xcode" } } diff --git a/test/tests/repository.js b/test/tests/repository.js index 29f2075099..32d483a576 100644 --- a/test/tests/repository.js +++ b/test/tests/repository.js @@ -49,6 +49,84 @@ describe("Repository", function() { assert.ok(this.repository instanceof Repository); }); + it("can explicitly free a repository", function() { + var initialCount = Repository.getSelfFreeingInstanceCount(); + + return Repository.open(reposPath) + .then(function(repository) { + assert.equal(Repository.getSelfFreeingInstanceCount(), initialCount + 1); + assert.equal(repository.free(), undefined); + assert.equal(Repository.getSelfFreeingInstanceCount(), initialCount); + assert.equal(repository.free(), undefined); + assert.equal(Repository.getSelfFreeingInstanceCount(), initialCount); + + return Repository.open(reposPath); + }) + .then(function(repository) { + assert.ok(repository.path()); + }); + }); + + it("keeps repository-owned handles usable after explicit free", function() { + var repository = this.repository; + return Promise.all([ + NodeGit.Treebuilder.create(repository, null), + NodeGit.Refdb.open(repository) + ]).then(function(handles) { + repository.free(); + assert.equal(handles[1].compress(), 0); + return handles[0].write(); + }).then(function(oid) { + assert.ok(oid); + }); + }); + + it("keeps children returned by already-queued work alive after free", function() { + var repository = this.repository; + var builder = NodeGit.Treebuilder.create(repository, null); + var refdb = NodeGit.Refdb.open(repository); + repository.free(); + + return Promise.all([builder, refdb]).then(function(handles) { + assert.equal(handles[1].compress(), 0); + return handles[0].write(); + }).then(function(oid) { + assert.ok(oid); + }); + }); + + it("preserves a commit's native owner but rejects its stale repo alias", function() { + var repository = this.repository; + return repository.getHeadCommit().then(function(commit) { + repository.free(); + assert.ok(commit.owner().path()); + return assert.rejects(commit.getTree(), /Repository has been freed/); + }); + }); + + it("finishes queued repository work after explicit free", function() { + var repository = this.repository; + var references = repository.getReferences(); + var statuses = repository.getStatus(); + repository.free(); + return Promise.all([references, statuses]).then(function(results) { + assert.ok(Array.isArray(results[0])); + assert.ok(Array.isArray(results[1])); + }); + }); + + it("rejects operations on a freed repository without invoking libgit2", function() { + var repository = this.repository; + repository.free(); + assert.throws(function() { repository.path(); }, /Repository has been freed/); + return Promise.all([ + assert.rejects(repository.getReferences(), /Repository has been freed/), + assert.rejects(NodeGit.Tree.lookup(repository, "0000000000000000000000000000000000000000"), + /Repository has been freed/), + assert.rejects(repository.getHeadCommit(), /Repository has been freed/) + ]); + }); + it("cannot open an invalid repository", function() { return Repository.open("repos/nonrepo") .then(null, function(err) { diff --git a/test/types/consumer.ts b/test/types/consumer.ts new file mode 100644 index 0000000000..b5219dd9ff --- /dev/null +++ b/test/types/consumer.ts @@ -0,0 +1,38 @@ +import { Config, Libgit2, Remote, RemoteCallbacks, Repository, StatusFile, TransferProgress, Treebuilder } from "../.."; + +async function useRepository(path: string): Promise { + const repo = await Repository.open(path); + const config: Config = await repo.config(); + const entry = await config.getEntry("user.name"); + const name: string = entry.name(); + const statuses: StatusFile[] = await repo.getStatus(); + const builder: Treebuilder = await Treebuilder.create(repo, null); + void builder; + void name; + void statuses; + repo.free(); + repo.free(); + // @ts-expect-error Explicit disposal is synchronous, not a Promise. + const result: Promise = repo.free(); + void result; +} + +const callbacks: RemoteCallbacks = { + pushUpdateReference: (refName, status) => { + if (status !== null) console.error(refName, status); + }, + pushTransferProgress: (current, total) => console.log(current, total), + transferProgress: progress => console.log(progress.totalObjects(), progress.receivedObjects()), +}; +function getProgress(progress: TransferProgress): number { + return progress.totalObjects(); +} +const mappedLimit: void = Libgit2.opts(Libgit2.OPT.SET_MWINDOW_MAPPED_LIMIT, 1024); +const currentLimit: number = Libgit2.opts(Libgit2.OPT.GET_MWINDOW_MAPPED_LIMIT); +void callbacks; +void getProgress; +void mappedLimit; +void currentLimit; +const completion: Remote.COMPLETION = Remote.COMPLETION.DOWNLOAD; +void completion; +void useRepository; diff --git a/types/LICENSE b/types/LICENSE new file mode 100644 index 0000000000..9e841e7a26 --- /dev/null +++ b/types/LICENSE @@ -0,0 +1,21 @@ + MIT License + + Copyright (c) Microsoft Corporation. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE diff --git a/types/annotated-commit.d.ts b/types/annotated-commit.d.ts new file mode 100644 index 0000000000..0230c12752 --- /dev/null +++ b/types/annotated-commit.d.ts @@ -0,0 +1,18 @@ +import { Oid } from "./oid"; +import { Reference } from "./reference"; +import { Repository } from "./repository"; + +export class AnnotatedCommit { + /** + * @param repo - repository that contains the given commit + * @param branchName - name of the (remote) branch + * @param remoteUrl - url of the remote + * @param id - the commit object id of the remote branch + */ + static fromFetchhead(repo: Repository, branchName: string, remoteUrl: string, id: Oid): Promise; + static fromRef(repo: Repository, ref: Reference): Promise; + static fromRevspec(repo: Repository, revspec: string): Promise; + static lookup(repo: Repository, id: Oid): Promise; + + id(): Oid; +} diff --git a/types/apply-options.d.ts b/types/apply-options.d.ts new file mode 100644 index 0000000000..d3c801364d --- /dev/null +++ b/types/apply-options.d.ts @@ -0,0 +1,8 @@ +import { ConvenientHunk } from "./convenient-hunk"; +import { DiffDelta } from "./diff-delta"; + +export class ApplyOptions { + deltaCb?: ((delta: DiffDelta, payload: any) => number) | undefined; + hunkCb?: ((hunk: ConvenientHunk, payload: any) => number) | undefined; + version?: number | undefined; +} diff --git a/types/apply.d.ts b/types/apply.d.ts new file mode 100644 index 0000000000..3dc5950f05 --- /dev/null +++ b/types/apply.d.ts @@ -0,0 +1,22 @@ +import { ApplyOptions } from "./apply-options"; +import { Diff } from "./diff"; +import { Index } from "./index_"; +import { Repository } from "./repository"; +import { Tree } from "./tree"; + +export namespace Apply { + const enum FLAGS { + CHECK = 1, + } + + const enum LOCATION { + WORKDIR = 0, + INDEX = 1, + BOTH = 2, + } +} + +export class Apply { + static apply(repo: Repository, diff: Diff, location: Apply.LOCATION, options: ApplyOptions): Promise; + static toTree(repo: Repository, preimage: Tree, diff: Diff, options: ApplyOptions): Promise; +} diff --git a/types/attr.d.ts b/types/attr.d.ts new file mode 100644 index 0000000000..9cb60ef0e5 --- /dev/null +++ b/types/attr.d.ts @@ -0,0 +1,38 @@ +import { Repository } from "./repository"; + +export namespace Attr { + const enum STATES { + UNSPECIFIED_T = 0, + TRUE_T = 1, + FALSE_T = 2, + VALUE_T = 3, + } +} + +export class Attr { + static addMacro(repo: Repository, name: string, values: string): number; + static cacheFlush(repo: Repository): void; + /** + * @param repo - The repository containing the path. + * @param flags - A combination of GIT_ATTR_CHECK... flags. + * @param path - The path to check for attributes. Relative paths are interpreted relative to the repo root. + * The file does not have to exist, but if it does not, then it will be treated as a plain file (not a directory). + * @param name - The name of the attribute to look up. + * @returns - Output of the value of the attribute. Use the GIT_ATTR_... + */ + static get(repo: Repository, flags: number, path: string, name: string): Promise; + /** + * @param repo - The repository containing the path. + * @param flags - A combination of GIT_ATTR_CHECK... flags. + * @param path - The path to check for attributes. Relative paths are interpreted relative to the repo root. + * The file does not have to exist, but if it does not, then it will be treated as a plain file (not a directory). + * @param numAttr - The number of attributes being looked up + * @param names - An array of num_attr strings containing attribute names. + */ + static getMany(repo: Repository, flags: number, path: string, numAttr: number, names: string): any[]; + /** + * @param attr - The attribute + * @returns - the value type for the attribute + */ + static value(attr: string): number; +} diff --git a/types/blame-hunk.d.ts b/types/blame-hunk.d.ts new file mode 100644 index 0000000000..8ad89e06f6 --- /dev/null +++ b/types/blame-hunk.d.ts @@ -0,0 +1,13 @@ +import { Oid } from "./oid"; +import { Signature } from "./signature"; + +export class BlameHunk { + linesInHunk(): number; + finalCommitId(): Oid; + finalStartLineNumber(): number; + finalSignature(): Signature; + origCommitId(): Oid; + origPath(): string; + origStartLineNumber(): number; + origSignature(): Signature; +} diff --git a/types/blame-options.d.ts b/types/blame-options.d.ts new file mode 100644 index 0000000000..fcf9be70be --- /dev/null +++ b/types/blame-options.d.ts @@ -0,0 +1,12 @@ +import { Oid } from "./oid"; + +export class BlameOptions { + version?: number | undefined; + flags?: number | undefined; + minMatchCharacters?: number | undefined; + newestCommit?: Oid | undefined; + oldestCommit?: Oid | undefined; + minLine?: number | undefined; + maxLine?: number | undefined; + [key: string]: any; +} diff --git a/types/blame.d.ts b/types/blame.d.ts new file mode 100644 index 0000000000..4cb7475b23 --- /dev/null +++ b/types/blame.d.ts @@ -0,0 +1,43 @@ +import { BlameHunk } from "./blame-hunk"; +import { BlameOptions } from "./blame-options"; +import { Repository } from "./repository"; + +export namespace Blame { + const enum FLAG { + NORMAL = 0, + TRACK_COPIES_SAME_FILE = 1, + TRACK_COPIES_SAME_COMMIT_MOVES = 2, + TRACK_COPIES_SAME_COMMIT_COPIES = 4, + TRACK_COPIES_ANY_COMMIT_COPIES = 8, + FIRST_PARENT = 16, + } +} + +export class Blame { + /** + * Retrieve the blame of a file + * + * @param repo - Repository that contains the file + * @param path - to the file to get the blame of + * @param [options] - Options for the blame + */ + static file(repo: Repository, path: string, options?: BlameOptions): Promise; + /** + * @param opts - The git_blame_options struct to initialize + * @param version - Version of struct; pass GIT_BLAME_OPTIONS_VERSION + */ + static initOptions(opts: BlameOptions, version: number): number; + + buffer(buffer: string, bufferLen: number): Promise; + + /** + * @returns - the hunk at the given index, or NULL on error + */ + getHunkByIndex(index: number): BlameHunk; + /** + * @returns - the hunk that contains the given line, or NULL on error + */ + getHunkByLine(lineNo: number): BlameHunk; + + getHunkCount(): number; +} diff --git a/types/blob.d.ts b/types/blob.d.ts new file mode 100644 index 0000000000..902e7941f4 --- /dev/null +++ b/types/blob.d.ts @@ -0,0 +1,39 @@ +import { WriteStream } from "fs"; +import { Oid } from "./oid"; +import { Repository } from "./repository"; +import { Wrapper } from "./wrapper"; + +export class Blob { + /** + * @param repo - repository where to blob will be written + * @param buffer - data to be written into the blob + * @param len - length of the data + * @returns - return the id of the written blob + */ + static createFromBuffer(repo: Repository, buffer: Buffer, len: number): Promise; + /** + * @param repo - repository where the blob will be written. this repository can be bare or not + * @param path - file from which the blob will be created + */ + static createFromDisk(repo: Repository, path: string): Promise; + static createFromStream(repo: Repository, hintPath: string): Promise; + /** + * @param repo - repository where the blob will be written. this repository cannot be bare + * @param relativePath - file from which the blob will be created, relative to the repository's working dir + * @returns - 0 or an error code + */ + static createFromWorkdir(repo: Repository, relativePath: string): Promise; + static filteredContent(blob: Blob, as_path: string, check_for_binary_data: number): Promise; + static lookup(repo: Repository, id: string | Oid | Blob): Promise; + static lookupPrefix(repo: Repository, id: Oid, len: number): Promise; + + id(): Oid; + isBinary(): number; + owner(): Repository; + rawcontent(): Wrapper; + rawsize(): number; + content(): Buffer; + toString(): string; + filemode(): number; + dup(): Promise; +} diff --git a/types/branch.d.ts b/types/branch.d.ts new file mode 100644 index 0000000000..81942aa1cd --- /dev/null +++ b/types/branch.d.ts @@ -0,0 +1,30 @@ +import { AnnotatedCommit } from "./annotated-commit"; +import { Commit } from "./commit"; +import { Reference } from "./reference"; +import { Repository } from "./repository"; + +export namespace Branch { + const enum BRANCH { + LOCAL = 1, + REMOTE = 2, + ALL = 3, + } +} + +export class Branch { + static create(repo: Repository, branchName: string, target: Commit, force: number): Promise; + static createFromAnnotated( + repository: Repository, + branchName: string, + commit: AnnotatedCommit, + force: number, + ): Promise; + static delete(branch: Reference): number; + static isHead(branch: Reference): number; + static iteratorNew(repo: Repository, listFlags: number): Promise; + static lookup(repo: Repository, branchName: string, branchType: Branch.BRANCH): Promise; + static move(branch: Reference, newBranchName: string, force: number): Promise; + static name(ref: Reference): Promise; + static setUpstream(branch: Reference, upstreamName: string | null): Promise; + static upstream(branch: Reference): Promise; +} diff --git a/types/buf.d.ts b/types/buf.d.ts new file mode 100644 index 0000000000..5a34e11cbd --- /dev/null +++ b/types/buf.d.ts @@ -0,0 +1,12 @@ +/// + +export class Buf { + containsNul(): number; + + grow(targetSize: number): Promise; + isBinary(): number; + set(data: Buffer, datalen: number): Promise; + ptr: string; + asize: number; + size: number; +} diff --git a/types/cert-host-key.d.ts b/types/cert-host-key.d.ts new file mode 100644 index 0000000000..62e318d55d --- /dev/null +++ b/types/cert-host-key.d.ts @@ -0,0 +1,8 @@ +import { Cert } from "./cert"; + +export class CertHostkey { + parent: Cert; + type: Cert.TYPE; + hashMd5: string; + hashSha1: string; +} diff --git a/types/cert-x509.d.ts b/types/cert-x509.d.ts new file mode 100644 index 0000000000..235d594902 --- /dev/null +++ b/types/cert-x509.d.ts @@ -0,0 +1,7 @@ +import { Cert } from "./cert"; + +export class CertX509 { + data: Buffer; + len: number; + parent: Cert; +} diff --git a/types/cert.d.ts b/types/cert.d.ts new file mode 100644 index 0000000000..bb573009bc --- /dev/null +++ b/types/cert.d.ts @@ -0,0 +1,17 @@ +export namespace Cert { + const enum TYPE { + NONE = 0, + X509 = 1, + HOSTKEY_LIBSSH2 = 2, + STRARRAY = 3, + } + + const enum SSH { + MD5 = 1, + SHA1 = 2, + } +} + +export class Cert { + certType: Cert.TYPE; +} diff --git a/types/checkout-options.d.ts b/types/checkout-options.d.ts new file mode 100644 index 0000000000..83f6701492 --- /dev/null +++ b/types/checkout-options.d.ts @@ -0,0 +1,27 @@ +import { Index } from "./index"; +import { Strarray } from "./str-array"; +import { Tree } from "./tree"; + +export class CheckoutOptions { + version?: number | undefined; + checkoutStrategy?: number | undefined; + disableFilters?: number | undefined; + dirMode?: number | undefined; + fileMode?: number | undefined; + fileOpenFlags?: number | undefined; + notifyFlags?: number | undefined; + notifyCb?: any; + notifyPayload?: undefined; + progressCb?: any; + progressPayload?: undefined; + paths?: Strarray | string | string[] | undefined; + baseline?: Tree | undefined; + baselineIndex?: Index | undefined; + targetDirectory?: string | undefined; + ancestorLabel?: string | undefined; + ourLabel?: string | undefined; + theirLabel?: string | undefined; + perfdataCb?: any; + perfdataPayload?: undefined; + [key: string]: any; +} diff --git a/types/checkout.d.ts b/types/checkout.d.ts new file mode 100644 index 0000000000..be6739dfe8 --- /dev/null +++ b/types/checkout.d.ts @@ -0,0 +1,61 @@ +import { CheckoutOptions } from "./checkout-options"; +import { Commit } from "./commit"; +import { Index } from "./index"; +import { Oid } from "./oid"; +import { Reference } from "./reference"; +import { Repository } from "./repository"; +import { Tree } from "./tree"; + +export namespace Checkout { + const enum NOTIFY { + NONE = 0, + CONFLICT = 1, + DIRTY = 2, + UPDATED = 4, + UNTRACKED = 8, + IGNORED = 16, + ALL = 65535, + } + + const enum STRATEGY { + NONE = 0, + SAFE = 1, + FORCE = 2, + RECREATE_MISSING = 4, + ALLOW_CONFLICTS = 16, + REMOVE_UNTRACKED = 32, + REMOVE_IGNORED = 64, + UPDATE_ONLY = 128, + DONT_UPDATE_INDEX = 256, + NO_REFRESH = 512, + SKIP_UNMERGED = 1024, + USE_OURS = 2048, + USE_THEIRS = 4096, + DISABLE_PATHSPEC_MATCH = 8192, + SKIP_LOCKED_DIRECTORIES = 262144, + DONT_OVERWRITE_IGNORED = 524288, + CONFLICT_STYLE_MERGE = 1048576, + CONFLICT_STYLE_DIFF3 = 2097152, + DONT_REMOVE_EXISTING = 4194304, + DONT_WRITE_INDEX = 8388608, + UPDATE_SUBMODULES = 65536, + UPDATE_SUBMODULES_IF_CHANGED = 131072, + } +} + +export class Checkout { + /** + * Patch head checkout to automatically coerce objects. + */ + static head(repo: Repository, options?: CheckoutOptions): Promise; + /** + * Patch index checkout to automatically coerce objects. + */ + static index(repo: Repository, The: Index, options?: CheckoutOptions): Promise; + + static initOptions(opts: CheckoutOptions, version: number): number; + /** + * Patch tree checkout to automatically coerce objects. + */ + static tree(repo: Repository, treeish: Oid | Tree | Commit | Reference, options?: CheckoutOptions): Promise; +} diff --git a/types/cherry-pick-options.d.ts b/types/cherry-pick-options.d.ts new file mode 100644 index 0000000000..b8fbb74f6f --- /dev/null +++ b/types/cherry-pick-options.d.ts @@ -0,0 +1,9 @@ +import { CheckoutOptions } from "./checkout-options"; +import { MergeOptions } from "./merge-options"; + +export interface CherrypickOptions { + version?: number | undefined; + mainline?: number | undefined; + mergeOpts?: MergeOptions | undefined; + checkoutOpts?: CheckoutOptions | undefined; +} diff --git a/types/cherry-pick.d.ts b/types/cherry-pick.d.ts new file mode 100644 index 0000000000..e13ea1f5c9 --- /dev/null +++ b/types/cherry-pick.d.ts @@ -0,0 +1,22 @@ +import { CherrypickOptions } from "./cherry-pick-options"; +import { Commit } from "./commit"; +import { MergeOptions } from "./merge-options"; +import { Repository } from "./repository"; + +export class Cherrypick { + /** + * Cherrypick a commit and, changing the index and working directory + */ + static cherrypick(repo: Repository, commit: Commit, options?: CherrypickOptions): Promise; + /** + * Cherrypicks the given commit against "our" commit, producing an index that reflects the result of the cherrypick. The index is not backed by a repo. + */ + static commit( + repo: Repository, + cherrypickCommit: Commit, + ourCommit: Commit, + mainline: number, + mergeOptions?: MergeOptions, + ): Promise; + static initOptions(opts: CherrypickOptions, version: number): number; +} diff --git a/types/clone-options.d.ts b/types/clone-options.d.ts new file mode 100644 index 0000000000..7b907e01c7 --- /dev/null +++ b/types/clone-options.d.ts @@ -0,0 +1,13 @@ +import { CheckoutOptions } from "./checkout-options"; +import { FetchOptions } from "./fetch-options"; + +export class CloneOptions { + version?: number | undefined; + checkoutOpts?: CheckoutOptions | undefined; + fetchOpts?: FetchOptions | undefined; + bare?: number | undefined; + local?: number | undefined; + checkoutBranch?: string | undefined; + repositoryCbPayload?: any; + remoteCbPayload?: any; +} diff --git a/types/clone.d.ts b/types/clone.d.ts new file mode 100644 index 0000000000..6b7bc73e93 --- /dev/null +++ b/types/clone.d.ts @@ -0,0 +1,16 @@ +import { CloneOptions } from "./clone-options"; +import { Repository } from "./repository"; + +export namespace Clone { + const enum LOCAL { + AUTO = 0, + LOCAL = 1, + NO_LOCAL = 2, + NO_LINKS = 3, + } +} + +/** + * Patch repository cloning to automatically coerce objects. + */ +export function Clone(url: string, localPath: string, options?: CloneOptions): Promise; diff --git a/types/commit-graph.d.ts b/types/commit-graph.d.ts new file mode 100644 index 0000000000..b817ef5411 --- /dev/null +++ b/types/commit-graph.d.ts @@ -0,0 +1,4 @@ +/** Native commit-graph handle; this build exposes no graph operations. */ +export class CommitGraph { + static readonly COMMIT_GRAPH_SPLIT_STRATEGY: { readonly SINGLE_FILE: 0 }; +} diff --git a/types/commit.d.ts b/types/commit.d.ts new file mode 100644 index 0000000000..5b4c211350 --- /dev/null +++ b/types/commit.d.ts @@ -0,0 +1,148 @@ +import { EventEmitter } from "events"; + +import { Buf } from "./buf"; +import { Diff } from "./diff"; +import { Error } from "./error"; +import { Object } from "./object"; +import { Oid } from "./oid"; +import { Repository } from "./repository"; +import { Signature } from "./signature"; +import { Tree } from "./tree"; +import { TreeEntry } from "./tree-entry"; + +export interface HistoryEventEmitter extends EventEmitter { + start(): void; +} + +export class Commit { + static create( + repo: Repository, + updateRef: string, + author: Signature, + committer: Signature, + messageEncoding: string, + message: string, + tree: Tree, + parentCount: number, + parents: any[], + ): Oid; + static createV( + id: Oid, + repo: Repository, + updateRef: string, + author: Signature, + committer: Signature, + messageEncoding: string, + message: string, + tree: Tree, + parentCount: number, + ): number; + /** + * Retrieves the commit pointed to by the oid + */ + static lookup(repo: Repository, id: string | Oid | Commit): Promise; + static lookupPrefix(repo: Repository, id: Oid, len: number): Promise; + static createWithSignature( + repo: Repository, + commitContent: string, + signature: string, + signatureField: string, + ): Promise; + + amend( + updateRef: string, + author: Signature, + committer: Signature, + messageEncoding: string, + message: string, + tree: Tree | Oid, + ): Promise; + amendWithSignature( + updateRef: string, + author: Signature, + committer: Signature, + messageEncoding: string, + message: string, + tree: Tree | Oid, + onSignature: ( + data: string, + ) => + | Promise<{ code: Error.CODE; field?: string | undefined; signedData: string }> + | { code: Error.CODE; field?: string | undefined; signedData: string }, + ): Promise; + author(): Signature; + committer(): Signature; + + headerField(field: string): Promise; + id(): Oid; + message(): string; + messageEncoding(): string; + messageRaw(): string; + nthGenAncestor(n: number): Promise; + owner(): Repository; + parent(n: number): Promise; + parentId(n: number): Oid; + parentcount(): number; + rawHeader(): string; + summary(): string; + time(): number; + timeOffset(): number; + tree(treeOut: Tree): number; + treeId(): Oid; + /** + * Retrieve the SHA. + */ + sha(): string; + /** + * Retrieve the commit time as a unix timestamp. + */ + timeMs(): number; + /** + * Retrieve the commit time as a Date object. + */ + date(): Date; + /** + * Get the tree associated with this commit. + */ + getTree(): Promise; + /** + * Retrieve the entry represented by path for this commit. Path must be relative to repository root. + */ + getEntry(path: string): Promise; + /** + * Walk the history from this commit backwards. + * An EventEmitter is returned that will emit a "commit" event for each commit in the history, and one "end" + * event when the walk is completed. Don't forget to call start() on the returned EventEmitter. + */ + history(): HistoryEventEmitter; + /** + * Retrieve the commit's parents as commit objects. + */ + getParents(limit: number, callback?: Function): Promise; + /** + * Retrieve the commit's parent shas. + */ + parents(): Oid[]; + /** + * Generate an array of diff trees showing changes between this commit and its parent(s). + */ + getDiff(callback?: Function): Promise; + /** + * Generate an array of diff trees showing changes between this commit and its parent(s). + */ + getDiffWithOptions(options: Object, callback?: Function): Promise; + /** + * The sha of this commit + */ + toString(): string; + dup(): Promise; + /** + * consists of a summary + */ + body(): string; + + getSignature(field?: string): Promise<{ + signature: string; + signedData: string; + }>; +} diff --git a/types/config.d.ts b/types/config.d.ts new file mode 100644 index 0000000000..8149d565d2 --- /dev/null +++ b/types/config.d.ts @@ -0,0 +1,52 @@ +import { Buf } from "./buf"; + +export namespace Config { + const enum LEVEL { + SYSTEM = 1, + XDG = 2, + GLOBAL = 3, + LOCAL = 4, + APP = 5, + HIGHEST_LEVEL = -1, + } + + const enum MAP { + FALSE = 0, + TRUE = 1, + INT32 = 2, + STRING = 3, + } +} + +export class ConfigEntry { + // the documentation says those are variables, + // but in reality they are functions + level(): number; + name(): string; + value(): string; +} + +export class Config { + static findGlobal(): Promise; // the docs says it's a buff but it's actually a string + static findProgramdata(): Promise; + static findSystem(): Promise; + static findXdg(): Promise; + static openDefault(): Promise; + static openOndisk(path: string): Promise; + + deleteEntry(name: string): number; + deleteMultivar(name: string, regexp: string): number; + getBool(name: string): Promise; + getEntry(name: string): Promise; + getInt32(name: string): Promise; + getInt64(name: string): Promise; + getPath(name: string): Promise; // the docs says Buf but it's actually a string + getStringBuf(name: string): Promise; + lock(transaction: any): number; + setBool(name: string, value: number): Promise; + setInt32(name: string, value: number): Promise; + setInt64(name: string, value: number): Promise; + setMultivar(name: string, regexp: string, value: string): Promise; + setString(name: string, value: string): Promise; + snapshot(): Promise; +} diff --git a/types/convenient-hunk.d.ts b/types/convenient-hunk.d.ts new file mode 100644 index 0000000000..1a3f39ce84 --- /dev/null +++ b/types/convenient-hunk.d.ts @@ -0,0 +1,37 @@ +import { DiffLine } from "./diff-line"; + +export class ConvenientHunk { + /** + * Diff header string that represents the context of this hunk + * of the diff. Something like `@@ -169,14 +167,12 @@ ...` + */ + header(): string; + /** + * The length of the header + */ + headerLen(): number; + /** + * The lines in this hunk + */ + lines(): Promise; + /** + * The number of new lines in the hunk + */ + newLines(): number; + /** + * The starting offset of the first new line in the file + */ + newStart(): number; + /** + * The number of old lines in the hunk + */ + oldLines(): number; + /** + * The starting offset of the first old line in the file + */ + oldStart(): number; + /** + * Number of lines in this hunk + */ + size(): number; +} diff --git a/types/convenient-patch.d.ts b/types/convenient-patch.d.ts new file mode 100644 index 0000000000..52eba400cf --- /dev/null +++ b/types/convenient-patch.d.ts @@ -0,0 +1,73 @@ +import { ConvenientHunk } from "./convenient-hunk"; +import { DiffFile } from "./diff-file"; + +export class ConvenientPatch { + /** + * Old attributes of the file + */ + oldFile(): DiffFile; + /** + * New attributes of the file + */ + newFile(): DiffFile; + /** + * The number of hunks in this patch + */ + size(): number; + /** + * The hunks in this patch + */ + hunks(): Promise; + /** + * The status of this patch (unmodified, added, deleted) + */ + status(): number; + /** + * The line statistics of this patch (#contexts, #added, #deleted) + */ + lineStats(): any; + /** + * Is this an unmodified patch? + */ + isUnmodified(): boolean; + /** + * Is this an added patch? + */ + isAdded(): boolean; + /** + * Is this a deleted patch? + */ + isDeleted(): boolean; + /** + * Is this an modified patch + */ + isModified(): boolean; + /** + * Is this a renamed patch? + */ + isRenamed(): boolean; + /** + * Is this a copied patch? + */ + isCopied(): boolean; + /** + * Is this an ignored patch? + */ + isIgnored(): boolean; + /** + * Is this an untracked patch? + */ + isUntracked(): boolean; + /** + * Is this a type change? + */ + isTypeChange(): boolean; + /** + * Is this an undreadable patch? + */ + isUnreadable(): boolean; + /** + * Is this a conflicted patch? + */ + isConflicted(): boolean; +} diff --git a/types/cred-user-pass-payload.d.ts b/types/cred-user-pass-payload.d.ts new file mode 100644 index 0000000000..95beeb9f3a --- /dev/null +++ b/types/cred-user-pass-payload.d.ts @@ -0,0 +1,4 @@ +export class CredUserpassPayload { + username: string; + password: string; +} diff --git a/types/cred-username.d.ts b/types/cred-username.d.ts new file mode 100644 index 0000000000..68593f7700 --- /dev/null +++ b/types/cred-username.d.ts @@ -0,0 +1,6 @@ +import { Cred } from "./cred"; + +export class CredUsername { + parent: Cred; + username: string; +} diff --git a/types/cred.d.ts b/types/cred.d.ts new file mode 100644 index 0000000000..013cf6826c --- /dev/null +++ b/types/cred.d.ts @@ -0,0 +1,25 @@ +export namespace Cred { + const enum TYPE { + USERPASS_PLAINTEXT = 1, + SSH_KEY = 2, + SSH_CUSTOM = 4, + DEFAULT = 8, + SSH_INTERACTIVE = 16, + USERNAME = 32, + SSH_MEMORY = 64, + } +} + +/** + * @deprecated Replaced with `Credential` + */ +export class Cred { + static defaultNew(): Cred; + static sshKeyFromAgent(username: string): Cred; + static sshKeyMemoryNew(username: string, publicKey: string, privateKey: string, passphrase: string): Promise; + static sshKeyNew(username: string, publicKey: string, privateKey: string, passphrase: string): Cred; + static usernameNew(username: string): Promise; + static userpassPlaintextNew(username: string, password: string): Cred; + + hasUsername(): number; +} diff --git a/types/credential.d.ts b/types/credential.d.ts new file mode 100644 index 0000000000..a0ee3edade --- /dev/null +++ b/types/credential.d.ts @@ -0,0 +1,25 @@ +export namespace Credential { + const enum TYPE { + USERPASS_PLAINTEXT = 1, + SSH_KEY = 2, + SSH_CUSTOM = 4, + DEFAULT = 8, + SSH_INTERACTIVE = 16, + USERNAME = 32, + SSH_MEMORY = 64, + } +} + +export class Credential { + static defaultNew(): Credential; + static sshKeyFromAgent(username: string): Credential; + static sshKeyMemoryNew( + username: string, + publicKey: string, + privateKey: string, + passphrase: string, + ): Promise; + static sshKeyNew(username: string, publicKey: string, privateKey: string, passphrase: string): Credential; + static usernameNew(username: string): Promise; + static userpassPlaintextNew(username: string, password: string): Credential; +} diff --git a/types/cvar-map.d.ts b/types/cvar-map.d.ts new file mode 100644 index 0000000000..f7c4b227d0 --- /dev/null +++ b/types/cvar-map.d.ts @@ -0,0 +1,5 @@ +export class CvarMap { + cvarType: number; + strMatch: string; + mapValue: number; +} diff --git a/types/describe-format-options.d.ts b/types/describe-format-options.d.ts new file mode 100644 index 0000000000..ee76bd49e9 --- /dev/null +++ b/types/describe-format-options.d.ts @@ -0,0 +1,7 @@ +export class DescribeFormatOptions { + version?: number | undefined; + abbreviatedSize?: number | undefined; + alwaysUseLongFormat?: number | undefined; + dirtySuffix?: string | undefined; + [key: string]: any; +} diff --git a/types/describe-options.d.ts b/types/describe-options.d.ts new file mode 100644 index 0000000000..9a4c3c9435 --- /dev/null +++ b/types/describe-options.d.ts @@ -0,0 +1,9 @@ +export class DescribeOptions { + version?: number | undefined; + maxCandidatesTags?: number | undefined; + describeStrategy?: number | undefined; + pattern?: string | undefined; + onlyFollowFirstParent?: number | undefined; + showCommitOidAsFallback?: number | undefined; + [key: string]: any; +} diff --git a/types/diff-binary-file.d.ts b/types/diff-binary-file.d.ts new file mode 100644 index 0000000000..029d418c02 --- /dev/null +++ b/types/diff-binary-file.d.ts @@ -0,0 +1,8 @@ +import { Object } from "./object"; + +export class DiffBinaryFile { + type: Object.TYPE; + data: string; + datalen: number; + inflatedlen: number; +} diff --git a/types/diff-binary.d.ts b/types/diff-binary.d.ts new file mode 100644 index 0000000000..c0dd9bb97d --- /dev/null +++ b/types/diff-binary.d.ts @@ -0,0 +1,15 @@ +import { DiffBinaryFile } from "./diff-binary-file"; + +export namespace DiffBinary { + const enum DIFF_BINARY { + NONE = 0, + LITERAL = 1, + DELTA = 2, + } +} + +export class DiffBinary { + oldFile: DiffBinaryFile; + newFile: DiffBinaryFile; + containsData: DiffBinary.DIFF_BINARY; +} diff --git a/types/diff-delta.d.ts b/types/diff-delta.d.ts new file mode 100644 index 0000000000..92ac8851b8 --- /dev/null +++ b/types/diff-delta.d.ts @@ -0,0 +1,10 @@ +import { DiffFile } from "./diff-file"; + +export class DiffDelta { + status: () => number; + flags: () => number; + similarity: () => number; + nfiles: () => number; + oldFile: () => DiffFile; + newFile: () => DiffFile; +} diff --git a/types/diff-file.d.ts b/types/diff-file.d.ts new file mode 100644 index 0000000000..8aca667c37 --- /dev/null +++ b/types/diff-file.d.ts @@ -0,0 +1,24 @@ +import { Oid } from "./oid"; + +export class DiffFile { + /** + * Returns the file's flags + */ + flags(): number; + /** + * Returns the file's Oid + */ + id(): Oid; + /** + * Returns the file's mode + */ + mode(): number; + /** + * Returns the file's path + */ + path(): string; + /** + * Returns the file's size + */ + size(): number; +} diff --git a/types/diff-hunk.d.ts b/types/diff-hunk.d.ts new file mode 100644 index 0000000000..629758859e --- /dev/null +++ b/types/diff-hunk.d.ts @@ -0,0 +1,9 @@ +/** One hunk within a native diff patch. */ +export class DiffHunk { + oldStart(): number; + oldLines(): number; + newStart(): number; + newLines(): number; + headerLen(): number; + header(): string | null; +} diff --git a/types/diff-line.d.ts b/types/diff-line.d.ts new file mode 100644 index 0000000000..aaaaeeac4b --- /dev/null +++ b/types/diff-line.d.ts @@ -0,0 +1,16 @@ +export class DiffLine { + /** + * The relevant line + */ + content(): string; + /** + * The non utf8 translated text + */ + rawContent(): string; + origin(): number; + oldLineno(): number; + newLineno(): number; + numLines(): number; + contentLen(): number; + contentOffset(): number; +} diff --git a/types/diff-options.d.ts b/types/diff-options.d.ts new file mode 100644 index 0000000000..fa0a3ca8a0 --- /dev/null +++ b/types/diff-options.d.ts @@ -0,0 +1,18 @@ +import { Strarray } from "./str-array"; + +export interface DiffOptions { + version?: number | undefined; + flags?: number | undefined; + ignoreSubmodules?: number | undefined; + pathspec?: Strarray | string | string[] | undefined; + notifyCb?: Function | undefined; + contextLines?: number | undefined; + interhunkLines?: number | undefined; + idAbbrev?: number | undefined; + maxSize?: number | undefined; + oldPrefix?: string | undefined; + newPrefix?: string | undefined; + payload?: any; + progressCb?: any; + [key: string]: any; +} diff --git a/types/diff-perf-data.d.ts b/types/diff-perf-data.d.ts new file mode 100644 index 0000000000..5dfca09670 --- /dev/null +++ b/types/diff-perf-data.d.ts @@ -0,0 +1,5 @@ +export class DiffPerfdata { + version: number; + statCalls: number; + oidCalculations: number; +} diff --git a/types/diff-stats.d.ts b/types/diff-stats.d.ts new file mode 100644 index 0000000000..45b10efebf --- /dev/null +++ b/types/diff-stats.d.ts @@ -0,0 +1,25 @@ +import { Buf } from "./buf"; + +export class DiffStats { + /** + * @returns - total number of deletions in the diff + */ + deletions(): Number; + + /** + * @returns - total number of files changed in the diff + */ + filesChanged(): Number; + + /** + * @returns - total number of insertions in the diff + */ + insertions(): Number; + + /** + * @param format - Formatting option. + * @param width - Target width for output (only affects GIT_DIFF_STATS_FULL) + * @returns - buffer to store the formatted diff statistics in. + */ + toBuf(format: Number, width: Number): Promise; +} diff --git a/types/diff.d.ts b/types/diff.d.ts new file mode 100644 index 0000000000..1f209b2b4b --- /dev/null +++ b/types/diff.d.ts @@ -0,0 +1,168 @@ +import { Blob } from "./blob"; +import { Buf } from "./buf"; +import { ConvenientPatch } from "./convenient-patch"; +import { DiffDelta } from "./diff-delta"; +import { DiffOptions } from "./diff-options"; +import { DiffPerfdata } from "./diff-perf-data"; +import { DiffStats } from "./diff-stats"; +import { Index } from "./index_"; +import { Repository } from "./repository"; +import { Strarray } from "./str-array"; +import { Tree } from "./tree"; + +export interface DiffFindOptions { + version?: number | undefined; + flags?: number | undefined; + renameThreshold?: number | undefined; + renameFromRewriteThreshold?: number | undefined; + copyThreshold?: number | undefined; + breakRewriteThreshold?: number | undefined; + renameLimit?: number | undefined; +} + +export namespace Diff { + const enum DELTA { + UNMODIFIED = 0, + ADDED = 1, + DELETED = 2, + MODIFIED = 3, + RENAMED = 4, + COPIED = 5, + IGNORED = 6, + UNTRACKED = 7, + TYPECHANGE = 8, + UNREADABLE = 9, + CONFLICTED = 10, + } + + const enum FIND { + BY_CONFIG = 0, + RENAMES = 1, + RENAMES_FROM_REWRITES = 2, + COPIES = 4, + COPIES_FROM_UNMODIFIED = 8, + REWRITES = 16, + BREAK_REWRITES = 32, + AND_BREAK_REWRITES = 48, + FOR_UNTRACKED = 64, + ALL = 255, + IGNORE_LEADING_WHITESPACE = 0, + IGNORE_WHITESPACE = 4096, + DONT_IGNORE_WHITESPACE = 8192, + EXACT_MATCH_ONLY = 16384, + BREAK_REWRITES_FOR_RENAMES_ONLY = 32768, + REMOVE_UNMODIFIED = 65536, + } + + const enum FLAG { + BINARY = 1, + NOT_BINARY = 2, + VALID_ID = 4, + EXISTS = 8, + } + + const enum FORMAT { + PATCH = 1, + PATCH_HEADER = 2, + RAW = 3, + NAME_ONLY = 4, + NAME_STATUS = 5, + } + + const enum FORMAT_EMAIL_FLAGS { + FORMAT_EMAIL_NONE = 0, + FORMAT_EMAIL_EXCLUDE_SUBJECT_PATCH_MARKER = 1, + } + + const enum LINE { + CONTEXT = 32, + ADDITION = 43, + DELETION = 45, + CONTEXT_EOFNL = 61, + ADD_EOFNL = 62, + DEL_EOFNL = 60, + FILE_HDR = 70, + HUNK_HDR = 72, + BINARY = 66, + } + + const enum OPTION { + NORMAL = 0, + REVERSE = 1, + INCLUDE_IGNORED = 2, + RECURSE_IGNORED_DIRS = 4, + INCLUDE_UNTRACKED = 8, + RECURSE_UNTRACKED_DIRS = 16, + INCLUDE_UNMODIFIED = 32, + INCLUDE_TYPECHANGE = 64, + INCLUDE_TYPECHANGE_TREES = 128, + IGNORE_FILEMODE = 256, + IGNORE_SUBMODULES = 512, + IGNORE_CASE = 1024, + INCLUDE_CASECHANGE = 2048, + DISABLE_PATHSPEC_MATCH = 4096, + SKIP_BINARY_CHECK = 8192, + ENABLE_FAST_UNTRACKED_DIRS = 16384, + UPDATE_INDEX = 32768, + INCLUDE_UNREADABLE = 65536, + INCLUDE_UNREADABLE_AS_UNTRACKED = 131072, + FORCE_TEXT = 1048576, + FORCE_BINARY = 2097152, + IGNORE_WHITESPACE = 4194304, + IGNORE_WHITESPACE_CHANGE = 8388608, + IGNORE_WHITESPACE_EOL = 16777216, + SHOW_UNTRACKED_CONTENT = 33554432, + SHOW_UNMODIFIED = 67108864, + PATIENCE = 268435456, + MINIMAL = 536870912, + SHOW_BINARY = 1073741824, + } + + const enum STATS_FORMAT { + STATS_NONE = 0, + STATS_FULL = 1, + STATS_SHORT = 2, + STATS_NUMBER = 4, + STATS_INCLUDE_SUMMARY = 8, + } +} + +export class Diff { + /** + * Directly run a diff between a blob and a buffer. + */ + static blobToBuffer( + oldBlob?: Blob, + oldAsPath?: string, + buffer?: string, + bufferAsPath?: string, + opts?: DiffOptions, + fileCb?: Function, + binaryCb?: Function, + hunkCb?: Function, + lineCb?: Function, + ): Promise; + static fromBuffer(content: string, contentLen: number): Promise; + static indexToWorkdir(repo: Repository, index?: Index, opts?: DiffOptions): Promise; + static indexToIndex(repo: Repository, oldIndex: Index, newIndex: Index, opts?: DiffOptions): Promise; + static treeToIndex(repo: Repository, oldTree?: Tree, index?: Index, opts?: DiffOptions): Promise; + static treeToTree(repo: Repository, oldTree?: Tree, new_tree?: Tree, opts?: DiffOptions): Promise; + static treeToWorkdir(repo: Repository, oldTree?: Tree, opts?: DiffOptions): Promise; + static treeToWorkdirWithIndex(repo: Repository, oldTree?: Tree, opts?: DiffOptions): Promise; + + findSimilar(options?: DiffFindOptions): Promise; + getDelta(idx: number): DiffDelta; + getPerfdata(): Promise; + numDeltas(): number; + /** + * Retrieve patches in this difflist + */ + patches(): Promise; + merge(from: Diff): Promise; + toBuf(format: Diff.FORMAT): Promise; + + /** + * @returns - Structure containg the diff statistics. + */ + getStats(): Promise; +} diff --git a/types/enums.d.ts b/types/enums.d.ts new file mode 100644 index 0000000000..e2e200f037 --- /dev/null +++ b/types/enums.d.ts @@ -0,0 +1,41 @@ +export namespace Enums { + const enum CVAR { + FALSE = 0, + TRUE = 1, + INT32 = 2, + string = 3, + } + + const enum DIRECTION { + FETCH = 0, + PUSH = 1, + } + + const enum FEATURE { + THREADS = 1, + HTTPS = 2, + SSH = 4, + } + + const enum IDXENTRY_EXTENDED_FLAG { + IDXENTRY_INTENT_TO_ADD = 8192, + IDXENTRY_SKIP_WORKTREE = 16384, + IDXENTRY_EXTENDED2 = 32768, + S = 24576, + IDXENTRY_UPDATE = 1, + IDXENTRY_REMOVE = 2, + IDXENTRY_UPTODATE = 4, + IDXENTRY_ADDED = 8, + IDXENTRY_HASHED = 16, + IDXENTRY_UNHASHED = 32, + IDXENTRY_WT_REMOVE = 64, + IDXENTRY_CONFLICTED = 128, + IDXENTRY_UNPACKED = 256, + IDXENTRY_NEW_SKIP_WORKTREE = 512, + } + + const enum INDXENTRY_FLAG { + IDXENTRY_EXTENDED = 16384, + IDXENTRY_VALID = 32768, + } +} diff --git a/types/error.d.ts b/types/error.d.ts new file mode 100644 index 0000000000..3f24a5a35c --- /dev/null +++ b/types/error.d.ts @@ -0,0 +1,68 @@ +export namespace Error { + const enum ERROR { + GITERR_NONE = 0, + GITERR_NOMEMORY = 1, + GITERR_OS = 2, + GITERR_INVALID = 3, + GITERR_REFERENCE = 4, + GITERR_ZLIB = 5, + GITERR_REPOSITORY = 6, + GITERR_CONFIG = 7, + GITERR_REGEX = 8, + GITERR_ODB = 9, + GITERR_INDEX = 10, + GITERR_OBJECT = 11, + GITERR_NET = 12, + GITERR_TAG = 13, + GITERR_TREE = 14, + GITERR_INDEXER = 15, + GITERR_SSL = 16, + GITERR_SUBMODULE = 17, + GITERR_THREAD = 18, + GITERR_STASH = 19, + GITERR_CHECKOUT = 20, + GITERR_FETCHHEAD = 21, + GITERR_MERGE = 22, + GITERR_SSH = 23, + GITERR_FILTER = 24, + GITERR_REVERT = 25, + GITERR_CALLBACK = 26, + GITERR_CHERRYPICK = 27, + GITERR_DESCRIBE = 28, + GITERR_REBASE = 29, + GITERR_FILESYSTEM = 30, + } + + const enum CODE { + OK = 0, + ERROR = -1, + ENOTFOUND = -3, + EEXISTS = -4, + EAMBIGUOUS = -5, + EBUFS = -6, + EUSER = -7, + EBAREREPO = -8, + EUNBORNBRANCH = -9, + EUNMERGED = -10, + ENONFASTFORWARD = -11, + EINVALIDSPEC = -12, + ECONFLICT = -13, + ELOCKED = -14, + EMODIFIED = -15, + EAUTH = -16, + ECERTIFICATE = -17, + EAPPLIED = -18, + EPEEL = -19, + EEOF = -20, + EINVALID = -21, + EUNCOMMITTED = -22, + EDIRECTORY = -23, + PASSTHROUGH = -30, + ITEROVER = -31, + } +} + +export class Error { + message: string; + klass: number; +} diff --git a/types/fetch-options.d.ts b/types/fetch-options.d.ts new file mode 100644 index 0000000000..90316d78d9 --- /dev/null +++ b/types/fetch-options.d.ts @@ -0,0 +1,13 @@ +import { RemoteCallbacks } from "./remote-callbacks"; +import { Strarray } from "./str-array"; + +export class FetchOptions { + version?: number | undefined; + callbacks?: RemoteCallbacks | undefined; + prune?: number | undefined; + updateFetchhead?: number | undefined; + downloadTags?: number | undefined; + customHeaders?: Strarray | string | string[] | undefined; + proxyOpts?: any; + [key: string]: any; +} diff --git a/types/fetch.d.ts b/types/fetch.d.ts new file mode 100644 index 0000000000..00aa58caef --- /dev/null +++ b/types/fetch.d.ts @@ -0,0 +1,13 @@ +import { FetchOptions } from "./fetch-options"; + +export namespace Fetch { + const enum PRUNE { + GIT_FETCH_PRUNE_UNSPECIFIED = 0, + GIT_FETCH_PRUNE = 1, + GIT_FETCH_NO_PRUNE = 2, + } +} + +export class Fetch { + static initOptions(opts: FetchOptions, version: number): number; +} diff --git a/types/filter-list.d.ts b/types/filter-list.d.ts new file mode 100644 index 0000000000..f99241611d --- /dev/null +++ b/types/filter-list.d.ts @@ -0,0 +1,12 @@ +/// +import { Blob } from "./blob"; +import { Repository } from "./repository"; + +/** An ordered set of filters loaded for a repository path. */ +export class FilterList { + static load(repo: Repository, blob: Blob | null, path: string, mode: number, flags: number): Promise; + + applyToBlob(blob: Blob): Promise; + applyToData(data: string | Buffer): Promise; + applyToFile(repo: Repository, path: string): Promise; +} diff --git a/types/filter-registry.d.ts b/types/filter-registry.d.ts new file mode 100644 index 0000000000..0d7d02fe12 --- /dev/null +++ b/types/filter-registry.d.ts @@ -0,0 +1,14 @@ +import { Buf } from "./buf"; +import { FilterSource } from "./filter-source"; + +/** Callbacks may return an error code directly or asynchronously. */ +export interface RegisteredFilter { + attributes?: string; + check(source: FilterSource, attributeValue: string): number | void | Promise; + apply(to: Buf, from: Buf, source: FilterSource): number | void | Promise; +} + +export const FilterRegistry: { + register(name: string, filter: RegisteredFilter, priority: number): Promise; + unregister(name: string): Promise; +}; diff --git a/types/filter-source.d.ts b/types/filter-source.d.ts new file mode 100644 index 0000000000..01b3880b89 --- /dev/null +++ b/types/filter-source.d.ts @@ -0,0 +1,12 @@ +import { Oid } from "./oid"; +import { Repository } from "./repository"; + +/** The source of data supplied to a registered filter callback. */ +export class FilterSource { + repo(): Promise; + path(): string | undefined; + filemode(): number; + id(): Oid | undefined; + mode(): number; + flags(): number; +} diff --git a/types/filter.d.ts b/types/filter.d.ts new file mode 100644 index 0000000000..fb8e60e331 --- /dev/null +++ b/types/filter.d.ts @@ -0,0 +1,35 @@ +import { WriteStream } from "fs"; + +import { Blob } from "./blob"; +import { Buf } from "./buf"; +import { Repository } from "./repository"; + +export namespace Filter { + const enum FLAG { + DEFAULT = 0, + ALLOW_UNSAFE = 1, + } + + const enum MODE { + TO_WORKTREE = 0, + SMUDGE = 0, + TO_ODB = 1, + CLEAN = 1, + } +} + +export class Filter { + static listContains(filters: any, name: string): number; + static listLength(fl: any): number; + static listNew(repo: Repository, mode: number, options: number): Promise; + static listStreamBlob(filters: any, blob: Blob, target: WriteStream): number; + static listStreamData(filters: any, data: Buf, target: WriteStream): number; + static listStreamFile(filters: any, repo: Repository, path: string, target: WriteStream): number; + static unregister(name: string): number; + + lookup(name: string): Filter; + register(name: string, priority: number): number; + version: number; + attributes: string; + stream: Function; +} diff --git a/types/git-err.d.ts b/types/git-err.d.ts new file mode 100644 index 0000000000..6d42b9c01d --- /dev/null +++ b/types/git-err.d.ts @@ -0,0 +1,8 @@ +import { Error } from "./error"; + +export class Giterr { + static errClear(): void; + static errLast(): Error; + static errSetOom(): void; + static errSetString(errorClass: number, string: string): void; +} diff --git a/types/graph.d.ts b/types/graph.d.ts new file mode 100644 index 0000000000..83f7132d63 --- /dev/null +++ b/types/graph.d.ts @@ -0,0 +1,7 @@ +import { Oid } from "./oid"; +import { Repository } from "./repository"; + +export class Graph { + static aheadBehind(repo: Repository, local: Oid, upstream: Oid): Promise; + static descendantOf(repo: Repository, commit: Oid, ancestor: Oid): Promise; +} diff --git a/types/hash-sig.d.ts b/types/hash-sig.d.ts new file mode 100644 index 0000000000..3700fb5c7d --- /dev/null +++ b/types/hash-sig.d.ts @@ -0,0 +1,15 @@ +export namespace Hashsig { + const enum OPTION { + NORMAL = 0, + IGNORE_WHITESPACE = 1, + SMART_WHITESPACE = 2, + ALLOW_SMALL_FILES = 4, + } +} + +export class Hashsig { + static create(buf: string, buflen: number, opts: number): Promise; + static createFromFile(path: string, opts: number): Promise; + + compare(b: Hashsig): number; +} diff --git a/types/ignore.d.ts b/types/ignore.d.ts new file mode 100644 index 0000000000..66ca4a5e04 --- /dev/null +++ b/types/ignore.d.ts @@ -0,0 +1,7 @@ +import { Repository } from "./repository"; + +export class Ignore { + static addRule(repo: Repository, rules: string): number; + static clearInternalRules(repo: Repository): number; + static pathIsIgnored(repo: Repository, path: string): Promise; +} diff --git a/types/index-entry.d.ts b/types/index-entry.d.ts new file mode 100644 index 0000000000..9c0e1c93b0 --- /dev/null +++ b/types/index-entry.d.ts @@ -0,0 +1,21 @@ +import { Oid } from "./oid"; + +export interface IndexTime { + seconds(): number; + nanoseconds(): number; +} + +export class IndexEntry { + ctime: IndexTime; + mtime: IndexTime; + dev: number; + ino: number; + mode: number; + uid: number; + gid: number; + fileSize: number; + id: Oid; + flags: number; + flagsExtended: number; + path: string; +} diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 0000000000..dafaa8f5d1 --- /dev/null +++ b/types/index.d.ts @@ -0,0 +1,121 @@ +export { AnnotatedCommit } from "./annotated-commit"; +export { Apply } from "./apply"; +export { ApplyOptions } from "./apply-options"; +export { Attr } from "./attr"; +export { Blame } from "./blame"; +export { BlameHunk } from "./blame-hunk"; +export { BlameOptions } from "./blame-options"; +export { Blob } from "./blob"; +export { Branch } from "./branch"; +export { Buf } from "./buf"; +export { Cert } from "./cert"; +export { CertHostkey } from "./cert-host-key"; +export { CertX509 } from "./cert-x509"; +export { Checkout } from "./checkout"; +export { CheckoutOptions } from "./checkout-options"; +export { Cherrypick } from "./cherry-pick"; +export { CherrypickOptions } from "./cherry-pick-options"; +export { Clone } from "./clone"; +export { CloneOptions } from "./clone-options"; +export { Commit } from "./commit"; +export { CommitGraph } from "./commit-graph"; +export { Config, ConfigEntry } from "./config"; +export { ConvenientHunk } from "./convenient-hunk"; +export { ConvenientPatch } from "./convenient-patch"; +export { Cred } from "./cred"; +export { CredUserpassPayload } from "./cred-user-pass-payload"; +export { CredUsername } from "./cred-username"; +export { Credential } from "./credential"; +export { CvarMap } from "./cvar-map"; +export { DescribeFormatOptions } from "./describe-format-options"; +export { DescribeOptions } from "./describe-options"; +export { Diff, DiffFindOptions } from "./diff"; +export { DiffBinary } from "./diff-binary"; +export { DiffBinaryFile } from "./diff-binary-file"; +export { DiffDelta } from "./diff-delta"; +export { DiffFile } from "./diff-file"; +export { DiffHunk } from "./diff-hunk"; +export { DiffLine } from "./diff-line"; +export { DiffOptions } from "./diff-options"; +export { DiffPerfdata } from "./diff-perf-data"; +export { DiffStats } from "./diff-stats"; +export { Enums } from "./enums"; +export { Error } from "./error"; +export { Fetch } from "./fetch"; +export { FetchOptions } from "./fetch-options"; +export { Filter } from "./filter"; +export { FilterList } from "./filter-list"; +export { FilterRegistry, RegisteredFilter } from "./filter-registry"; +export { FilterSource } from "./filter-source"; +export { Giterr } from "./git-err"; +export { Graph } from "./graph"; +export { Hashsig } from "./hash-sig"; +export { Ignore } from "./ignore"; +export { IndexEntry } from "./index-entry"; +export { Index } from "./index_"; +export { Indexer } from "./indexer"; +export { Libgit2 } from "./lib-git2"; +export { Mailmap } from "./mailmap"; +export { Merge } from "./merge"; +export { MergeFileInput } from "./merge-file-input"; +export { MergeFileOptions } from "./merge-file-options"; +export { MergeFileResult } from "./merge-file-result"; +export { MergeOptions } from "./merge-options"; +export { Note } from "./note"; +export { Object } from "./object"; +export { Odb } from "./odb"; +export { OdbExpandId } from "./odb-expand-id"; +export { OdbObject } from "./odb-object"; +export { Oid } from "./oid"; +export { Oidarray } from "./oid-array"; +export { Openssl } from "./open-ssl"; +export { Patch } from "./patch"; +export { Packbuilder } from "./pack-builder"; +export { Pathspec } from "./path-spec"; +export { Proxy } from "./proxy"; +export { ProxyOptions } from "./proxy-options"; +export { Push } from "./push"; +export { PushOptions } from "./push-options"; +export { PushUpdate } from "./push-update"; +export { Rebase, RebaseOptions } from "./rebase"; +export { RebaseOperation } from "./rebase-operation"; +export { Refdb } from "./ref-db"; +export { Reflog, ReflogEntry } from "./ref-log"; +export { Refspec } from "./ref-spec"; +export { Reference } from "./reference"; +export { Remote } from "./remote"; +export { RemoteCallbacks } from "./remote-callbacks"; +export { RemoteHead } from "./remote-head"; +export { Repository, RepositoryInitOptions, RepositoryStatistics } from "./repository"; +export { Reset } from "./reset"; +export { Revparse } from "./rev-parse"; +export { Revwalk } from "./rev-walk"; +export { Revert } from "./revert"; +export { Signature } from "./signature"; +export { Stash } from "./stash"; +export { Status } from "./status"; +export { StatusEntry } from "./status-entry"; +export { StatusFile } from "./status-file"; +export { StatusFileOptions } from "./status-file-options"; +export { StatusList } from "./status-list"; +export { StatusOptions } from "./status-options"; +export { Strarray } from "./str-array"; +export { Submodule } from "./submodule"; +export { SubmoduleUpdateOptions } from "./submodule-update-options"; +export { Tag } from "./tag"; +export { Time } from "./time"; +export { TransferProgress } from "./transfer-progress"; +export { Transaction } from "./transaction"; +export { Transport } from "./transport"; +export { Tree } from "./tree"; +export { Treebuilder } from "./tree-builder"; +export { TreeEntry } from "./tree-entry"; +export { TreeUpdate } from "./tree-update"; +export { Worktree } from "./worktree"; +export { WorktreeAddOptions } from "./worktree-add-options"; +export { WorktreePruneOptions } from "./worktree-prune-options"; +export { Utils } from "./utils"; +export function getNumberOfTrackedObjects(): number; +export const version: string; +declare const _: typeof Promise; +export { _ as Promise }; diff --git a/types/index_.d.ts b/types/index_.d.ts new file mode 100644 index 0000000000..93b463ec9a --- /dev/null +++ b/types/index_.d.ts @@ -0,0 +1,59 @@ +import { IndexEntry } from "./index-entry"; +import { Oid } from "./oid"; +import { Repository } from "./repository"; +import { Strarray } from "./str-array"; +import { Tree } from "./tree"; + +export namespace Index { + const enum ADD_OPTION { + ADD_DEFAULT = 0, + ADD_FORCE = 1, + ADD_DISABLE_PATHSPEC_MATCH = 2, + ADD_CHECK_PATHSPEC = 4, + } + + const enum CAP { + IGNORE_CASE = 1, + NO_FILEMODE = 2, + NO_SYMLINKS = 4, + FROM_OWNER = -1, + } +} + +export class Index { + static entryIsConflict(entry: IndexEntry): boolean; + static entryStage(entry: IndexEntry): number; + static open(indexPath: string): Promise; + + add(sourceEntry: IndexEntry): number; + addAll(pathspec?: Strarray | string | string[], flags?: number, callback?: Function): Promise; + addByPath(path: string): Promise; + caps(): number; + checksum(): Oid; + clear(): number; + conflictAdd(ancestorEntry: IndexEntry, ourEntry: IndexEntry, theirEntry: IndexEntry): number; + conflictCleanup(): number; + conflictGet(path: string): Promise; + conflictRemove(path: string): number; + entryCount(): number; + getByIndex(n: number): IndexEntry; + getByPath(path: string, stage?: number): IndexEntry; + hasConflicts(): boolean; + owner(): Repository; + path(): string; + read(force: number): number; + readTree(tree: Tree): number; + remove(path: string, stage: number): number; + removeAll(pathspec: Strarray | string | string[], callback?: Function): Promise; + removeByPath(path: string): Promise; + removeDirectory(dir: string, stage: number): number; + setCaps(caps: number): number; + updateAll(pathspec: Strarray | string | string[], callback?: Function): Promise; + write(): Promise; + writeTree(): Promise; + writeTreeTo(repo: Repository): Promise; + entries(): IndexEntry[]; + findPrefix(atPos: number, prefix: string): number; + setVersion(version: number): number; + version(): number; +} diff --git a/types/indexer.d.ts b/types/indexer.d.ts new file mode 100644 index 0000000000..73c58364c6 --- /dev/null +++ b/types/indexer.d.ts @@ -0,0 +1,8 @@ +import { Oid } from "./oid"; +import { TransferProgress } from "./transfer-progress"; + +export class Indexer { + commit(stats: TransferProgress): number; + + hash(): Oid; +} diff --git a/types/lib-git2.d.ts b/types/lib-git2.d.ts new file mode 100644 index 0000000000..13597fea5e --- /dev/null +++ b/types/lib-git2.d.ts @@ -0,0 +1,28 @@ +export namespace Libgit2 { + const enum OPT { + GET_MWINDOW_SIZE = 0, + SET_MWINDOW_SIZE = 1, + GET_MWINDOW_MAPPED_LIMIT = 2, + SET_MWINDOW_MAPPED_LIMIT = 3, + GET_SEARCH_PATH = 4, + SET_SEARCH_PATH = 5, + SET_CACHE_OBJECT_LIMIT = 6, + SET_CACHE_MAX_SIZE = 7, + ENABLE_CACHING = 8, + GET_CACHED_MEMORY = 9, + GET_TEMPLATE_PATH = 10, + SET_TEMPLATE_PATH = 11, + SET_SSL_CERT_LOCATIONS = 12, + } +} + +export class Libgit2 { + static features(): number; + static init(): number; + static opts(option: Libgit2.OPT.GET_MWINDOW_SIZE | Libgit2.OPT.GET_MWINDOW_MAPPED_LIMIT | Libgit2.OPT.GET_CACHED_MEMORY): number; + static opts(option: Libgit2.OPT.GET_TEMPLATE_PATH): string; + static opts(option: Libgit2.OPT.GET_SEARCH_PATH, level: number): string; + static opts(option: Libgit2.OPT.SET_MWINDOW_SIZE | Libgit2.OPT.SET_MWINDOW_MAPPED_LIMIT | Libgit2.OPT.ENABLE_CACHING, value: number): void; + static shutdown(): number; + static version(major: number, minor: number, rev: number): void; +} diff --git a/types/mailmap.d.ts b/types/mailmap.d.ts new file mode 100644 index 0000000000..365a256ceb --- /dev/null +++ b/types/mailmap.d.ts @@ -0,0 +1,13 @@ +import { Repository } from "./repository"; +import { Signature } from "./signature"; + +/** Resolves names and addresses against Git mailmap entries. */ +export class Mailmap { + static create(): Promise; + static fromBuffer(buffer: string, length: number): Promise; + static fromRepository(repo: Repository): Promise; + + addEntry(realName: string, realEmail: string, replaceName: string, replaceEmail: string): Promise; + resolve(name: string, email: string): Promise<{ real_name: string | null; real_email: string | null }>; + resolveSignature(signature: Signature): Promise; +} diff --git a/types/merge-file-input.d.ts b/types/merge-file-input.d.ts new file mode 100644 index 0000000000..f49bd446ca --- /dev/null +++ b/types/merge-file-input.d.ts @@ -0,0 +1,7 @@ +export interface MergeFileInput { + version: number; + ptr: string; + size: number; + path: string; + mode: number; +} diff --git a/types/merge-file-options.d.ts b/types/merge-file-options.d.ts new file mode 100644 index 0000000000..22a21d7044 --- /dev/null +++ b/types/merge-file-options.d.ts @@ -0,0 +1,9 @@ +export interface MergeFileOptions { + version?: number | undefined; + ancestorLabel?: string | undefined; + ourLabel?: string | undefined; + theirLabel?: string | undefined; + favor?: number | undefined; + flags?: number | undefined; + [key: string]: any; +} diff --git a/types/merge-file-result.d.ts b/types/merge-file-result.d.ts new file mode 100644 index 0000000000..e6f2efcc3b --- /dev/null +++ b/types/merge-file-result.d.ts @@ -0,0 +1,7 @@ +export class MergeFileResult { + automergeable: number; + path: string; + mode: number; + ptr: string; + len: number; +} diff --git a/types/merge-options.d.ts b/types/merge-options.d.ts new file mode 100644 index 0000000000..86d087cdaf --- /dev/null +++ b/types/merge-options.d.ts @@ -0,0 +1,11 @@ +export class MergeOptions { + version?: number | undefined; + renameThreshold?: number | undefined; + targetLimit?: number | undefined; + fileFavor?: number | undefined; + fileFlags?: number | undefined; + defaultDriver?: string | undefined; + flags?: number | undefined; + recursionLimit?: number | undefined; + [key: string]: any; +} diff --git a/types/merge.d.ts b/types/merge.d.ts new file mode 100644 index 0000000000..601a10d4e5 --- /dev/null +++ b/types/merge.d.ts @@ -0,0 +1,70 @@ +import { AnnotatedCommit } from "./annotated-commit"; +import { CheckoutOptions } from "./checkout-options"; +import { Commit } from "./commit"; +import { Index } from "./index"; +import { MergeFileInput } from "./merge-file-input"; +import { MergeOptions } from "./merge-options"; +import { Oid } from "./oid"; +import { Oidarray } from "./oid-array"; +import { Repository } from "./repository"; +import { Tree } from "./tree"; + +export namespace Merge { + const enum ANALYSIS { + NONE = 0, + NORMAL = 1, + UP_TO_DATE = 2, + FASTFORWARD = 4, + UNBORN = 8, + } + + const enum FILE_FAVOR { + NORMAL = 0, + OURS = 1, + THEIRS = 2, + UNION = 3, + } + + const enum FILE_FLAGS { + FILE_DEFAULT = 0, + FILE_STYLE_MERGE = 1, + FILE_STYLE_DIFF3 = 2, + FILE_SIMPLIFY_ALNUM = 4, + FILE_IGNORE_WHITESPACE = 8, + FILE_IGNORE_WHITESPACE_CHANGE = 16, + FILE_IGNORE_WHITESPACE_EOL = 32, + FILE_DIFF_PATIENCE = 64, + FILE_DIFF_MINIMAL = 128, + } + + const enum PREFERENCE { + NONE = 0, + NO_FASTFORWARD = 1, + FASTFORWARD_ONLY = 2, + } + + const enum TREE_FLAG { + TREE_FIND_RENAMES = 1, + } +} + +export class Merge { + static merge( + repo: Repository, + theirHead: AnnotatedCommit, + mergeOpts?: MergeOptions, + checkoutOpts?: CheckoutOptions, + ): any; + static base(repo: Repository, one: Oid, two: Oid): Promise; + static bases(repo: Repository, one: Oid, two: Oid): Promise; + static commits(repo: Repository, ourCommit: Commit, theirCommit: Commit, options?: MergeOptions): any; + static fileInitInput(opts: MergeFileInput, version: number): number; + static initOptions(opts: MergeOptions, version: number): number; + static trees( + repo: Repository, + ancestorTree: Tree, + ourTree: Tree, + theirTree: Tree, + opts?: MergeOptions, + ): Promise; +} diff --git a/types/note.d.ts b/types/note.d.ts new file mode 100644 index 0000000000..1912d96960 --- /dev/null +++ b/types/note.d.ts @@ -0,0 +1,32 @@ +import { Oid } from "./oid"; +import { Repository } from "./repository"; +import { Signature } from "./signature"; + +export class Note { + static create( + repo: Repository, + notesRef: string, + author: Signature, + committer: Signature, + oid: Oid, + note: string, + force: number, + ): Promise; + static foreach(repo: Repository, notesRef: string, noteCb: Function, payload: any): Promise; + static iteratorNew(repo: Repository, notesRef: string): Promise; + static next(noteId: Oid, annotatedId: Oid, it: any): number; + static read(repo: Repository, notesRef: string, oid: Oid): Promise; + static remove( + repo: Repository, + notesRef: string, + author: Signature, + committer: Signature, + oid: Oid, + ): Promise; + + author(): Signature; + committer(): Signature; + + id(): Oid; + message(): string; +} diff --git a/types/object.d.ts b/types/object.d.ts new file mode 100644 index 0000000000..38a41cda1b --- /dev/null +++ b/types/object.d.ts @@ -0,0 +1,36 @@ +import { Buf } from "./buf"; +import { Oid } from "./oid"; +import { Repository } from "./repository"; + +export class Object { + static size(type: Object.TYPE): number; + static lookup(repo: Repository, id: Oid, type: Object.TYPE): Promise; + static lookupPrefix(repo: Repository, id: Oid, len: number, type: Object.TYPE): Promise; + static string2Type(str: string): Object.TYPE; + static type2String(type: Object.TYPE): string; + static typeisloose(type: Object.TYPE): number; + + dup(): Promise; + + id(): Oid; + lookupByPath(path: string, type: Object.TYPE): Promise; + owner(): Repository; + peel(targetType: number): Promise; + shortId(): Promise; + type(): number; +} + +export namespace Object { + const enum TYPE { + ANY = -2, + BAD = -1, + EXT1 = 0, + COMMIT = 1, + TREE = 2, + BLOB = 3, + TAG = 4, + EXT2 = 5, + OFS_DELTA = 6, + REF_DELTA = 7, + } +} diff --git a/types/odb-expand-id.d.ts b/types/odb-expand-id.d.ts new file mode 100644 index 0000000000..ac554433d5 --- /dev/null +++ b/types/odb-expand-id.d.ts @@ -0,0 +1,8 @@ +import { Object } from "./object"; +import { Oid } from "./oid"; + +export class OdbExpandId { + id: Oid; + length: number; + type: Object.TYPE; +} diff --git a/types/odb-object.d.ts b/types/odb-object.d.ts new file mode 100644 index 0000000000..d5c5f7cf33 --- /dev/null +++ b/types/odb-object.d.ts @@ -0,0 +1,10 @@ +import { Oid } from "./oid"; + +export class OdbObject { + data(): Buffer; + dup(): Promise; + + id(): Oid; + size(): number; + type(): number; +} diff --git a/types/odb.d.ts b/types/odb.d.ts new file mode 100644 index 0000000000..50e585c8a4 --- /dev/null +++ b/types/odb.d.ts @@ -0,0 +1,22 @@ +import { Object } from "./object"; +import { OdbExpandId } from "./odb-expand-id"; +import { OdbObject } from "./odb-object"; +import { Oid } from "./oid"; + +export namespace Odb { + const enum STREAM { + RDONLY = 2, + WRONLY = 4, + RW = 6, + } +} + +export class Odb { + static open(objectsDir: string): Promise; + + addDiskAlternate(path: string): number; + + read(id: Oid): Promise; + write(data: Buffer, len: number, type: Object.TYPE): Promise; + expandIds(ids: OdbExpandId, count: number): number; +} diff --git a/types/oid-array.d.ts b/types/oid-array.d.ts new file mode 100644 index 0000000000..11cac41dc6 --- /dev/null +++ b/types/oid-array.d.ts @@ -0,0 +1,6 @@ +import { Oid } from "./oid"; + +export class Oidarray { + ids: Oid; + count: number; +} diff --git a/types/oid.d.ts b/types/oid.d.ts new file mode 100644 index 0000000000..2aa65905f6 --- /dev/null +++ b/types/oid.d.ts @@ -0,0 +1,11 @@ +export class Oid { + static fromString(str: string): Oid; + cmp(b: Oid): number; + cpy(): Oid; + equal(b: Oid): number; + iszero(): number; + ncmp(b: Oid, len: number): number; + strcmp(str: string): number; + streq(str: string): number; + tostrS(): string; +} diff --git a/types/open-ssl.d.ts b/types/open-ssl.d.ts new file mode 100644 index 0000000000..f8370260d5 --- /dev/null +++ b/types/open-ssl.d.ts @@ -0,0 +1,3 @@ +export class Openssl { + static setLocking(): number; +} diff --git a/types/pack-builder.d.ts b/types/pack-builder.d.ts new file mode 100644 index 0000000000..e6dac0a253 --- /dev/null +++ b/types/pack-builder.d.ts @@ -0,0 +1,24 @@ +import { Oid } from "./oid"; +import { Repository } from "./repository"; +import { Revwalk } from "./rev-walk"; + +export namespace Packbuilder { + const enum STAGE { + ADDING_OBJECTS = 0, + DELTAFICATION = 1, + } +} + +export class Packbuilder { + static create(repo: Repository): Packbuilder; + + hash(): Oid; + insert(id: Oid, name: string): number; + insertCommit(id: Oid): number; + insertRecur(id: Oid, name: string): number; + insertTree(id: Oid): number; + insertWalk(walk: Revwalk): number; + objectCount(): number; + setThreads(n: number): number; + written(): number; +} diff --git a/types/patch.d.ts b/types/patch.d.ts new file mode 100644 index 0000000000..26d0e95d6d --- /dev/null +++ b/types/patch.d.ts @@ -0,0 +1,23 @@ +import { Blob } from "./blob"; +import { ConvenientPatch } from "./convenient-patch"; +import { Diff } from "./diff"; +import { DiffDelta } from "./diff-delta"; +import { DiffHunk } from "./diff-hunk"; +import { DiffLine } from "./diff-line"; +import { DiffOptions } from "./diff-options"; + +/** Native patch object, distinct from the convenient patch wrapper. */ +export class Patch { + static fromBlobs(oldBlob: Blob | null, oldPath: string | null, newBlob: Blob | null, newPath: string | null, options?: DiffOptions): Promise; + static fromDiff(diff: Diff, index: number): Promise; + static convenientFromDiff(diff: Diff, indexes?: number[]): Promise; + + getDelta(): DiffDelta; + getHunk(index: number): Promise<{ hunk: DiffHunk; linesInHunk: number }>; + getLineInHunk(hunkIndex: number, lineIndex: number): Promise; + lineStats(): { total_context: number; total_additions: number; total_deletions: number }; + numHunks(): number; + numLinesInHunk(index: number): number; + owner(): Diff; + size(includeContext: number, includeHunkHeaders: number, includeFileHeaders: number): number; +} diff --git a/types/path-spec.d.ts b/types/path-spec.d.ts new file mode 100644 index 0000000000..03b5c667e4 --- /dev/null +++ b/types/path-spec.d.ts @@ -0,0 +1,33 @@ +import { Diff } from "./diff"; +import { DiffDelta } from "./diff-delta"; +import { Index } from "./index"; +import { Repository } from "./repository"; +import { Strarray } from "./str-array"; +import { Tree } from "./tree"; + +export namespace Pathspec { + const enum FLAG { + DEFAULT = 0, + IGNORE_CASE = 1, + USE_CASE = 2, + NO_GLOB = 4, + NO_MATCH_ERROR = 8, + FIND_FAILURES = 16, + FAILURES_ONLY = 32, + } +} + +export class Pathspec { + static matchListDiffEntry(m: any, pos: number): DiffDelta; + static matchListEntry(m: any, pos: number): string; + static matchListEntrycount(m: any): number; + static matchListFailedEntry(m: any, pos: number): string; + static matchListFailedEntrycount(m: any): number; + static create(pathspec: Strarray | string | string[]): Pathspec; + + matchDiff(diff: Diff, flags: number): Promise; + matchIndex(index: Index, flags: number): Promise; + matchTree(tree: Tree, flags: number): Promise; + matchWorkdir(repo: Repository, flags: number): Promise; + matchesPath(flags: number, path: string): number; +} diff --git a/types/proxy-options.d.ts b/types/proxy-options.d.ts new file mode 100644 index 0000000000..a4940107da --- /dev/null +++ b/types/proxy-options.d.ts @@ -0,0 +1,9 @@ +export class ProxyOptions { + certificateCheck?: Function | undefined; + credentials?: Function | undefined; + payload?: any; + type?: number | undefined; + url?: string | undefined; + version?: number | undefined; + [key: string]: any; +} diff --git a/types/proxy.d.ts b/types/proxy.d.ts new file mode 100644 index 0000000000..ef68452a3e --- /dev/null +++ b/types/proxy.d.ts @@ -0,0 +1,5 @@ +import { ProxyOptions } from "./proxy-options"; + +export class Proxy { + static initOptions(opts: ProxyOptions, version: number): number; +} diff --git a/types/push-options.d.ts b/types/push-options.d.ts new file mode 100644 index 0000000000..48efa71353 --- /dev/null +++ b/types/push-options.d.ts @@ -0,0 +1,12 @@ +import { ProxyOptions } from "./proxy-options"; +import { RemoteCallbacks } from "./remote-callbacks"; +import { Strarray } from "./str-array"; + +export interface PushOptions { + version?: number | undefined; + pbParallelism?: number | undefined; + callbacks?: RemoteCallbacks | undefined; + customHeaders?: Strarray | string | string[] | undefined; + proxyOpts?: ProxyOptions | undefined; + [key: string]: any; +} diff --git a/types/push-update.d.ts b/types/push-update.d.ts new file mode 100644 index 0000000000..6f96eab917 --- /dev/null +++ b/types/push-update.d.ts @@ -0,0 +1,8 @@ +import { Oid } from "./oid"; + +export class PushUpdate { + srcRefname: string; + dstRefname: string; + src: Oid; + dst: Oid; +} diff --git a/types/push.d.ts b/types/push.d.ts new file mode 100644 index 0000000000..2f504e6ad2 --- /dev/null +++ b/types/push.d.ts @@ -0,0 +1,6 @@ +import { PushOptions } from "./push-options"; +import { RemoteCallbacks } from "./remote-callbacks"; + +export class Push { + static initOptions(opts: PushOptions, version: number): number; +} diff --git a/types/rebase-operation.d.ts b/types/rebase-operation.d.ts new file mode 100644 index 0000000000..a8d22f939a --- /dev/null +++ b/types/rebase-operation.d.ts @@ -0,0 +1,18 @@ +import { Oid } from "./oid"; + +export namespace RebaseOperation { + const enum REBASE_OPERATION { + PICK = 0, + REWORD = 1, + EDIT = 2, + SQUASH = 3, + FIXUP = 4, + EXEC = 5, + } +} + +export class RebaseOperation { + type(): number | null; + id(): Oid; + exec(): string | null; +} diff --git a/types/rebase.d.ts b/types/rebase.d.ts new file mode 100644 index 0000000000..939c048f17 --- /dev/null +++ b/types/rebase.d.ts @@ -0,0 +1,55 @@ +import { AnnotatedCommit } from "./annotated-commit"; +import { CheckoutOptions } from "./checkout-options"; +import { Index, MergeOptions, Tree } from "./index"; +import { Oid } from "./oid"; +import { RebaseOperation } from "./rebase-operation"; +import { Repository } from "./repository"; +import { Signature } from "./signature"; + +export interface RebaseOptions { + version?: number | null; + quiet?: number | null; + inmemory?: number | null; + rewriteNotesRef?: string | null; + mergeOptions?: MergeOptions | null; + checkoutOptions?: CheckoutOptions | null; + commitCreateCb?: + | (( + author: Signature, + committer: Signature, + message_encoding: string, + message: string, + tree: Tree, + parent_count: number, + parents: Oid[], + payload?: PayloadType, + ) => Oid) + | null; + payload?: PayloadType | null; +} + +export class Rebase { + static init( + repo: Repository, + branch: AnnotatedCommit | undefined | null, + upstream?: AnnotatedCommit | null, + onto?: AnnotatedCommit | null, + opts?: RebaseOptions | null, + ): Promise; + static initOptions(opts: RebaseOptions, version: number): number; + static open(repo: Repository, opts?: RebaseOptions): Promise; + + abort(): number; + commit( + author: Signature | undefined | null, + committer: Signature, + messageEncoding?: string | null, + message?: string | null, + ): Promise; + finish(signature?: Signature | null): number; + inmemoryIndex(index: Index): number; + next(): Promise; + operationByIndex(idx: number): RebaseOperation; + operationCurrent(): number; + operationEntrycount(): number; +} diff --git a/types/ref-db.d.ts b/types/ref-db.d.ts new file mode 100644 index 0000000000..9650b1e742 --- /dev/null +++ b/types/ref-db.d.ts @@ -0,0 +1,7 @@ +import { Repository } from "./repository"; + +export class Refdb { + static open(repo: Repository): Promise; + + compress(): number; +} diff --git a/types/ref-log.d.ts b/types/ref-log.d.ts new file mode 100644 index 0000000000..2fa87fc19c --- /dev/null +++ b/types/ref-log.d.ts @@ -0,0 +1,23 @@ +import { Oid } from "./oid"; +import { Repository } from "./repository"; +import { Signature } from "./signature"; + +export class Reflog { + static delete(repo: Repository, name: string): number; + static read(repo: Repository, name: string): Promise; + static rename(repo: Repository, oldName: string, name: string): number; + + append(id: Oid, committer: Signature, msg: string): number; + drop(idx: number, rewritePreviousEntry: number): number; + entryByIndex(idx: number): ReflogEntry; + entrycount(): number; + + write(): number; +} + +export class ReflogEntry { + committer(): Signature; + idNew(): Oid; + idOld(): Oid; + message(): string; +} diff --git a/types/ref-spec.d.ts b/types/ref-spec.d.ts new file mode 100644 index 0000000000..f9b33fac7b --- /dev/null +++ b/types/ref-spec.d.ts @@ -0,0 +1,10 @@ +export class Refspec { + static parse(input: string, is_fetch: number): Promise; + direction(): number; + dst(): string; + dstMatches(refname: string): number; + force(): number; + src(): string; + srcMatches(refname: string): number; + string(): string; +} diff --git a/types/reference.d.ts b/types/reference.d.ts new file mode 100644 index 0000000000..d7fafd0c3b --- /dev/null +++ b/types/reference.d.ts @@ -0,0 +1,84 @@ +import { Object } from "./object"; +import { Oid } from "./oid"; +import { Repository } from "./repository"; + +export namespace Reference { + const enum TYPE { + INVALID = 0, + DIRECT = 1, + /** @deprecated Use {@link DIRECT} instead. */ + OID = 1, + SYMBOLIC = 2, + ALL = 3, + /** @deprecated Use {@link ALL} instead. */ + LISTALL = 3, + } + + const enum NORMALIZE { + REF_FORMAT_NORMAL = 0, + REF_FORMAT_ALLOW_ONELEVEL = 1, + REF_FORMAT_REFSPEC_PATTERN = 2, + REF_FORMAT_REFSPEC_SHORTHAND = 4, + } +} + +export class Reference { + static create(repo: Repository, name: string, id: Oid, force: number, logMessage: string): Promise; + static createMatching( + repo: Repository, + name: string, + id: Oid, + force: number, + currentId: Oid, + logMessage: string, + ): Promise; + static dwim(repo: Repository, id: string | Reference, callback?: Function): Promise; + static ensureLog(repo: Repository, refname: string): number; + static hasLog(repo: Repository, refname: string): number; + static isValidName(refname: string): number; + static list(repo: Repository): Promise; + static lookup(repo: Repository, id: string | Reference, callback?: Function): Promise; + static nameToId(repo: Repository, name: string): Promise; + static normalizeName(bufferOut: string, bufferSize: number, name: string, flags: number): number; + static remove(repo: Repository, name: string): number; + static symbolicCreate( + repo: Repository, + name: string, + target: string, + force: number, + logMessage: string, + ): Promise; + static symbolicCreateMatching( + repo: Repository, + name: string, + target: string, + force: number, + currentValue: string, + logMessage: string, + ): Promise; + + cmp(ref2: Reference): number; + delete(): number; + isBranch(): number; + isNote(): number; + isRemote(): number; + isTag(): number; + name(): string; + owner(): Repository; + peel(type: Object.TYPE): Promise; + rename(newName: string, force: number, logMessage: string): Promise; + resolve(): Promise; + setTarget(id: Oid, logMessage: string): Promise; + shorthand(): string; + symbolicSetTarget(target: string, logMessage: string): Promise; + symbolicTarget(): string; + target(): Oid; + targetPeel(): Oid; + type(): number; + isValid(): boolean; + isConcrete(): boolean; + isSymbolic(): boolean; + toString(): string; + isHead(): boolean; + dup(): Promise; +} diff --git a/types/remote-callbacks.d.ts b/types/remote-callbacks.d.ts new file mode 100644 index 0000000000..f6f24b7eea --- /dev/null +++ b/types/remote-callbacks.d.ts @@ -0,0 +1,30 @@ +export class RemoteCallbacks { + version?: number | undefined; + credentials?: Function | undefined; + certificateCheck?: Function | undefined; + /** Progress callback for push operations */ + pushTransferProgress?: PushTransferProgressCallback; + /** Called for each pushed ref with the remote's rejection message, or null on success. */ + pushUpdateReference?: (refName: string, status: string | null) => unknown; + /** Progress callback for fetch and clone operations */ + transferProgress?: (progress: IndexerProgress) => unknown; + transport?: Function | undefined; + payload?: undefined; +} + +/** The third argument is currently unreliable in this fork; use object counts for progress. */ +export type PushTransferProgressCallback = ( + pushedObjects: number, + totalObjects: number, + pushedBytes: number, +) => unknown; + +export interface IndexerProgress { + indexedDeltas: () => number; + indexedObjects: () => number; + localObjects: () => number; + receivedBytes: () => number; + receivedObjects: () => number; + totalDeltas: () => number; + totalObjects: () => number; +} diff --git a/types/remote-head.d.ts b/types/remote-head.d.ts new file mode 100644 index 0000000000..af27caa1f2 --- /dev/null +++ b/types/remote-head.d.ts @@ -0,0 +1,10 @@ +import { Oid } from "./oid"; + +/** An advertised reference from a connected remote. */ +export class RemoteHead { + local(): number; + oid(): Oid; + loid(): Oid; + name(): string | null; + symrefTarget(): string | null; +} diff --git a/types/remote.d.ts b/types/remote.d.ts new file mode 100644 index 0000000000..8f0974e80f --- /dev/null +++ b/types/remote.d.ts @@ -0,0 +1,82 @@ +import { Enums } from "./enums"; +import { FetchOptions } from "./fetch-options"; +import { PushOptions } from "./push-options"; +import { Refspec } from "./ref-spec"; +import { RemoteCallbacks } from "./remote-callbacks"; +import { RemoteHead } from "./remote-head"; +import { Repository } from "./repository"; +import { Strarray } from "./str-array"; +import { TransferProgress } from "./transfer-progress"; + +export namespace Remote { + const enum COMPLETION { + DOWNLOAD = 0, + INDEXING = 1, + ERROR = 2, + } + const enum AUTOTAG_OPTION { + DOWNLOAD_TAGS_UNSPECIFIED = 0, + DOWNLOAD_TAGS_AUTO = 1, + DOWNLOAD_TAGS_NONE = 2, + DOWNLOAD_TAGS_ALL = 3, + } + + const enum COMPLETION_TYPE { + COMPLETION_DOWNLOAD = 0, + COMPLETION_INDEXING = 1, + COMPLETION_ERROR = 2, + } +} + +export class Remote { + static addFetch(repo: Repository, remote: string, refspec: string): number; + static addPush(repo: Repository, remote: string, refspec: string): number; + static create(repo: Repository, name: string, url: string): Promise; + static createAnonymous(repo: Repository, url: string): Promise; + static createDetached(url: string): Promise; + static createWithFetchspec(repo: Repository, name: string, url: string, fetch: string): Promise; + static delete(repo: Repository, name: string): Promise; + static initCallbacks(opts: RemoteCallbacks, version: number): number; + static isValidName(remoteName: string): boolean; + static list(repo: Repository): Promise; + static lookup(repo: Repository, name: string | Remote, callback?: Function): Promise; + static rename(repo: Repository, oldName: string, newName: string): Promise; + static setAutotag(repo: Repository, remote: string, value: number): number; + static setPushurl(repo: Repository, remote: string, url: string): number; + static setUrl(repo: Repository, remote: string, url: string): number; + + autotag(): number; + connect(direction: Enums.DIRECTION, callbacks: RemoteCallbacks, callback?: Function): Promise; + connected(): number; + defaultBranch(): Promise; + disconnect(): Promise; + download(refSpecs: any[], opts?: FetchOptions, callback?: Function): Promise; + dup(): Promise; + fetch(refSpecs: any[], opts: FetchOptions, message: string, callback?: Function): Promise; + + getFetchRefspecs(): Promise; + getPushRefspecs(): Promise; + getRefspec(n: number): Refspec; + name(): string; + owner(): Repository; + prune(callbacks: RemoteCallbacks): number; + pruneRefs(): number; + push(refSpecs: any[], options?: PushOptions, callback?: Function): Promise; + pushurl(): string; + refspecCount(): number; + stats(): TransferProgress; + + stop(): void; + updateTips( + callbacks: RemoteCallbacks, + updateFetchhead: number, + downloadTags: number, + reflogMessage: string, + ): number; + upload(refspecs: Strarray | string | string[], opts?: PushOptions): number; + url(): string; + /** + * Lists advertised references from a remote. You must connect to the remote before using referenceList. + */ + referenceList(): Promise; +} diff --git a/types/repository.d.ts b/types/repository.d.ts new file mode 100644 index 0000000000..7bb4888cb2 --- /dev/null +++ b/types/repository.d.ts @@ -0,0 +1,375 @@ +import { AnnotatedCommit } from "./annotated-commit"; +import { Blob } from "./blob"; +import { CheckoutOptions } from "./checkout-options"; +import { Commit } from "./commit"; +import { Config } from "./config"; +import { DiffLine } from "./diff-line"; +import { DiffOptions } from "./diff-options"; +import { Error } from "./error"; +import { FetchOptions } from "./fetch-options"; +import { Index } from "./index_"; +import { Merge } from "./merge"; +import { MergeOptions } from "./merge-options"; +import { Odb } from "./odb"; +import { Oid } from "./oid"; +import { Refdb } from "./ref-db"; +import { Reference } from "./reference"; +import { Rebase, RebaseOptions } from "./rebase"; +import { Remote } from "./remote"; +import { Revwalk } from "./rev-walk"; +import { Signature } from "./signature"; +import { StatusFile } from "./status-file"; +import { StatusOptions } from "./status-options"; +import { Submodule } from "./submodule"; +import { Tag } from "./tag"; +import { Tree } from "./tree"; +import { Treebuilder } from "./tree-builder"; +import { Worktree } from "./worktree"; + +export interface RepositoryInitOptions { + description?: string; + flags?: number; + initialHead?: string; + mode?: number; + originUrl?: string; + templatePath?: string; + version?: number; + workdirPath?: string; +} + +export interface RepositoryStatistics { + repositorySize: { + commits: { count: number; size: number }; + trees: { count: number; size: number; entries: number }; + blobs: { count: number; size: number }; + annotatedTags: { count: number }; + references: { count: number }; + }; + biggestObjects: { + commits: { maxSize: number; maxParents: number }; + trees: { maxEntries: number }; + blobs: { maxSize: number }; + }; + historyStructure: { maxDepth: number; maxTagDepth: number }; + biggestCheckouts: { + numDirectories: number; + maxPathDepth: number; + maxPathLength: number; + numFiles: number; + totalFileSize: number; + numSymlinks: number; + numSubmodules: number; + }; +} + +export class Repository { + /** Find the repository from a starting path and return its absolute path. */ + static discover(startPath: string, acrossFs: number, ceilingDirs?: string | null): Promise; + static getReferences(repo: Repository, type: Reference.TYPE, refNamesOnly?: false): Promise; + static getReferences(repo: Repository, type: Reference.TYPE, refNamesOnly: true): Promise; + static init(path: string, isBare: number): Promise; + static initExt(repoPath: string, options?: RepositoryInitOptions): Promise; + static open(path: string): Promise; + static openBare(barePath: string): Promise; + static openExt(path: string, flags?: number, ceilingDirs?: string): Promise; + static openFromWorktree(wt: Worktree): Promise; + static wrapOdb(odb: Odb): Promise; + + cleanup(): Promise; + commitParents(): Promise; + commondir(): string; + config(): Promise; + configSnapshot(): Promise; + detachHead(): number; + fetchheadForeach(callback: (refName: string, remoteUrl: string, oid: Oid, isMerge: number) => number | void | Promise): Promise; + /** Release the native repository. This instance must not be used after free(). */ + free(): void; + + getNamespace(): string | undefined; + getSubmodules(): Promise; + head(): Promise; + headDetached(): number; + headDetachedForWorktree(name: string): number; + headForWorktree(name: string): Promise; + headUnborn(): number; + ident(): { name: string | null; email: string | null }; + index(): Promise; + isBare(): number; + isEmpty(): number; + isShallow(): number; + isWorktree(): number; + itemPath(item: number): Promise; + mergeheadForeach(callback: (oid: Oid) => number | void | Promise): Promise; + messageRemove(): number; + odb(): Promise; + oidType(): number; + path(): string; + refdb(): Promise; + refreshReferences(): Promise; + setHead(refname: string): Promise; + setHeadDetached(commitish: Oid): number; + setHeadDetachedFromAnnotated(commitish: AnnotatedCommit): number; + setIdent(name: string, email: string): number; + setIndex(index?: Index | null): void; + setNamespace(nmspace: string): number; + setWorkdir(workdir: string, updateGitLink: number): number; + state(): number; + stateCleanup(): number; + statistics(): Promise; + submoduleCacheAll(): void; + submoduleCacheClear(): void; + workdir(): string | undefined; + /** + * Creates a branch with the passed in name pointing to the commit + */ + createBranch(name: string, commit: Commit | string | Oid, force?: boolean): Promise; + /** + * Look up a refs's commit. + */ + getReferenceCommit(name: string | Reference): Promise; + /** + * Look up a branch. Alias for getReference + */ + getBranch(name: string | Reference): Promise; + /** + * Look up a branch's most recent commit. Alias to getReferenceCommit + */ + getBranchCommit(name: string | Reference): Promise; + /** + * Gets the branch that HEAD currently points to Is an alias to head() + */ + getCurrentBranch(): Promise; + /** + * Lookup the reference with the given name. + */ + getReference(name: string | Reference): Promise; + /** + * Lookup references for a repository. + */ + getReferences(): Promise; + /** + * Lookup reference names for a repository. + */ + getReferenceNames(type: Reference.TYPE): Promise; + getCommit(string: string | Commit | Oid): Promise; + /** + * Retrieve the blob represented by the oid. + */ + getBlob(string: string | Oid): Promise; + /** + * Retrieve the tree represented by the oid. + */ + getTree(string: string | Oid): Promise; + createTag(string: string | Oid, name: string, message: string): Promise; + /** + * Creates a new lightweight tag + */ + createLightweightTag(string: string | Oid, name: string): Promise; + /** + * Retrieve the tag represented by the oid. + */ + getTag(string: string | Oid): Promise; + /** + * Retrieve the tag represented by the tag name. + */ + getTagByName(Short: string): Promise; + /** + * Deletes a tag from a repository by the tag name. + */ + deleteTagByName(Short: string): Promise; + /** + * Instantiate a new revision walker for browsing the Repository"s history. See also Commit.prototype.history() + */ + createRevWalk(): Revwalk; + /** + * Retrieve the master branch commit. + */ + getMasterCommit(): Promise; + /** + * Retrieve the commit that HEAD is currently pointing to + */ + getHeadCommit(): Promise; + createCommit( + updateRef: string | null, + author: Signature, + committer: Signature, + message: string, + Tree: Tree | Oid | string, + parents?: Array, + ): Promise; + createCommitWithSignature( + updateRef: string | null, + author: Signature, + committer: Signature, + message: string, + Tree: Tree | Oid | string, + parents: Array, + onSignature: ( + data: string, + ) => + | Promise<{ code: Error.CODE; field?: string | undefined; signedData: string }> + | { code: Error.CODE; field?: string | undefined; signedData: string }, + ): Promise; + /** + * Creates a new commit on HEAD from the list of passed in files + */ + createCommitOnHead(filesToAdd: string[], author: Signature, committer: Signature, message: string): Promise; + createCommitBuffer( + author: Signature, + committer: Signature, + message: string, + treeOid: Tree | Oid | string, + parents?: Array, + ): Promise; + /** + * Create a blob from a buffer + */ + createBlobFromBuffer(buffer: Buffer): Promise; + /** The JS wrapper ignores tree and currently calls Treebuilder.create(null), which rejects at runtime. */ + treeBuilder(tree?: Tree): Promise; + /** + * Gets the default signature for the default user and now timestamp + */ + defaultSignature(): Signature; + /** + * Lists out the names of remotes in the given repository. + */ + getRemoteNames(): Promise; + /** + * Lists out the remotes in the given repository. + */ + getRemotes(): Promise; + /** + * Gets a remote from the repo + */ + getRemote(remote: string | Remote): Promise; + /** + * Fetches from a remote + */ + fetch(remote: string | Remote, fetchOptions?: FetchOptions): Promise; + /** + * Fetches from all remotes. This is done in series due to deadlocking issues with fetching from many remotes that can happen. + */ + fetchAll(fetchOptions?: FetchOptions): Promise; + mergeBranches( + to: string | Reference, + from: string | Reference, + signature?: Signature, + mergePreference?: Merge.PREFERENCE, + mergeOptions?: MergeOptions, + mergeBranchOptions?: { + processMergeMessageCallback?: (message: string) => string | Promise; + signingCb?: (data: string) => + | { code: Error.CODE; field?: string; signedData: string } + | Promise<{ code: Error.CODE; field?: string; signedData: string }>; + }, + ): Promise; + /** + * Rebases a branch onto another branch + */ + rebaseBranches( + branch: string | Reference, + upstream: string | Reference, + onto?: string | Reference | null, + signature?: Signature | null, + beforeNextFn?: (rebase: Rebase) => void | Promise, + beforeFinishFn?: (summary: { + ontoName: string; + ontoSha: string; + originalHeadName: string; + originalHeadSha: string; + rebase: Rebase; + rewritten: string[][] | null; + }) => void | Promise, + rebaseOptions?: RebaseOptions, + ): Promise; + continueRebase( + signature?: Signature | null, + beforeNextFn?: (rebase: Rebase) => void | Promise, + beforeFinishFn?: (summary: { + ontoName: string; + ontoSha: string; + originalHeadName: string; + originalHeadSha: string; + rebase: Rebase; + rewritten: string[][] | null; + }) => void | Promise, + rebaseOptions?: RebaseOptions, + ): Promise; + /** + * Get the status of a repo to it's working directory + */ + getStatus(opts?: StatusOptions): Promise; + /** + * Return StatusFile wrappers with status and headToIndex/indexToWorkdir deltas (not raw StatusEntry objects). + */ + getStatusExt(opts?: StatusOptions): Promise; + /** + * Get the names of the submodules in the repository. + */ + getSubmoduleNames(): Promise; + /** + * This will set the HEAD to point to the reference and then attempt to update the index and working tree to match the content of the latest commit on that reference + */ + checkoutRef(reference: Reference, opts?: CheckoutOptions): Promise; + /** + * This will set the HEAD to point to the local branch and then attempt to update the index and working tree to match the content of the latest commit on that branch + */ + checkoutBranch(branch: string | Reference, opts?: CheckoutOptions): Promise; + /** + * Stages or unstages line selection of a specified file + */ + stageFilemode(filePath: string | string[], stageNew: boolean, additionalDiffOptions?: DiffOptions): Promise; + /** + * Stages or unstages line selection of a specified file + */ + stageLines(filePath: string, selectedLines: DiffLine[], isSelectionStaged: boolean, additionalDiffOptions?: DiffOptions): Promise; + /** + * Returns true if the repository is in the default NONE state. + */ + isDefaultState(): boolean; + /** + * Returns true if the repository is in the APPLY_MAILBOX or APPLY_MAILBOX_OR_REBASE state. + */ + isApplyingMailbox(): boolean; + /** + * Returns true if the repository is in the BISECT state. + */ + isBisecting(): boolean; + /** + * Returns true if the repository is in the CHERRYPICK state. + */ + isCherrypicking(): boolean; + /** + * Returns true if the repository is in the MERGE state. + */ + isMerging(): boolean; + /** + * Returns true if the repository is in the REBASE, REBASE_INTERACTIVE, or REBASE_MERGE state. + */ + isRebasing(): boolean; + /** + * Returns true if the repository is in the REVERT state. + */ + isReverting(): boolean; + /** + * Discard line selection of a specified file. Assumes selected lines are unstaged. + */ + discardLines(filePath: string, selectedLines: DiffLine[], additionalDiffOptions?: DiffOptions): Promise; + /** + * Grabs a fresh copy of the index from the repository. Invalidates all previously grabbed indexes + */ + refreshIndex(): Promise; +} + +export namespace Repository { + const enum INIT_FLAG { + BARE = 1, + NO_REINIT = 2, + NO_DOTGIT_DIR = 4, + MKDIR = 8, + MKPATH = 16, + EXTERNAL_TEMPLATE = 32, + RELATIVE_GITLINK = 64, + } +} diff --git a/types/reset.d.ts b/types/reset.d.ts new file mode 100644 index 0000000000..eece2b7c36 --- /dev/null +++ b/types/reset.d.ts @@ -0,0 +1,41 @@ +import { AnnotatedCommit } from "./annotated-commit"; +import { CheckoutOptions } from "./checkout-options"; +import { Commit } from "./commit"; +import { Repository } from "./repository"; +import { Strarray } from "./str-array"; +import { Tag } from "./tag"; + +export namespace Reset { + const enum TYPE { + SOFT = 1, + MIXED = 2, + HARD = 3, + } +} + +export class Reset { + /** + * Look up a refs's commit. + */ + static reset( + repo: Repository, + target: Commit | Tag, + resetType: Reset.TYPE, + checkoutOpts?: CheckoutOptions, + ): Promise; + /** + * Look up a refs's commit. + */ + static default(repo: Repository, target: Commit | Tag, pathspecs: Strarray | string | string[]): Promise; + /** + * Sets the current head to the specified commit oid and optionally resets the index and working tree to match. + * This behaves like reset but takes an annotated commit, which lets you specify which extended sha syntax string was specified by a user, allowing for more exact reflog messages. + * See the documentation for reset. + */ + static fromAnnotated( + repo: Repository, + commit: AnnotatedCommit, + resetType: number, + checkoutOpts: CheckoutOptions, + ): Promise; +} diff --git a/types/rev-parse.d.ts b/types/rev-parse.d.ts new file mode 100644 index 0000000000..d84f6c6842 --- /dev/null +++ b/types/rev-parse.d.ts @@ -0,0 +1,16 @@ +import { Object } from "./object"; +import { Reference } from "./reference"; +import { Repository } from "./repository"; + +export namespace Revparse { + const enum MODE { + SINGLE = 1, + RANGE = 2, + MERGE_BASE = 4, + } +} + +export class Revparse { + static ext(objectOut: Object, referenceOut: Reference, repo: Repository, spec: string): number; + static single(repo: Repository, spec: string): Promise; +} diff --git a/types/rev-walk.d.ts b/types/rev-walk.d.ts new file mode 100644 index 0000000000..f93478adde --- /dev/null +++ b/types/rev-walk.d.ts @@ -0,0 +1,55 @@ +import { Commit } from "./commit"; +import { Diff } from "./diff"; +import { Oid } from "./oid"; +import { Repository } from "./repository"; + +export namespace Revwalk { + const enum SORT { + NONE = 0, + TOPOLOGICAL = 1, + TIME = 2, + REVERSE = 4, + } + interface HistoryEntry { + commit: Commit; + status: Diff.DELTA; + newName: string; + oldName: string; + } +} + +export class Revwalk { + static create(repo: Repository): Revwalk; + + hide(commitId: Oid): number; + hideGlob(glob: string): number; + hideHead(): number; + hideRef(refname: string): number; + next(): Promise; + push(id: Oid): number; + pushGlob(glob: string): number; + pushHead(): number; + pushRange(range: string): number; + pushRef(refname: string): number; + repository(): Repository; + + reset(): void; + + simplifyFirstParent(): void; + /** + * Set the sort order for the revwalk. This function takes variable arguments like revwalk.sorting(NodeGit.RevWalk.Topological, NodeGit.RevWalk.Reverse). + */ + sorting(...sort: number[]): void; + commitWalk(maxCount: number): Promise; + fastWalk(maxCount: number): Promise; + fileHistoryWalk(filePath: string, maxCount: number): Promise; + /** + * Walk the history from the given oid. The callback is invoked for each commit; When the walk is over, the callback is invoked with (null, null). + */ + walk(oid: Oid, callback?: Function): Commit; + /** + * Walk the history grabbing commits until the checkFn called with the current commit returns false. + */ + getCommitsUntil(checkFn: Function): Promise; + getCommits(count: number): Promise; +} diff --git a/types/revert.d.ts b/types/revert.d.ts new file mode 100644 index 0000000000..e8da5741e6 --- /dev/null +++ b/types/revert.d.ts @@ -0,0 +1,27 @@ +import { CheckoutOptions } from "./checkout-options"; +import { Commit } from "./commit"; +import { Index } from "./index"; +import { MergeOptions } from "./merge-options"; +import { Repository } from "./repository"; + +export interface RevertOptions { + version?: number | undefined; + mainline?: number | undefined; + mergeOpts?: MergeOptions | undefined; + checkoutOpts?: CheckoutOptions | undefined; + [key: string]: any; +} + +export class Revert { + static revert(repo: Repository, commit: Commit, givenOpts?: RevertOptions): Promise; + /** + * Reverts the given commit against the given "our" commit, producing an index that reflects the result of the revert. + */ + static commit( + repo: Repository, + revertCommit: Commit, + ourCommit: Commit, + mainline: number, + mergeOptions?: MergeOptions, + ): Promise; +} diff --git a/types/signature.d.ts b/types/signature.d.ts new file mode 100644 index 0000000000..59492c4605 --- /dev/null +++ b/types/signature.d.ts @@ -0,0 +1,16 @@ +import { Repository } from "./repository"; +import { Time } from "./time"; + +export class Signature { + static default(repo: Repository): Promise; + static create(name: string, email: string, time: number, offset: number): Signature; + static now(name: string, email: string): Signature; + static fromBuffer(buf: string): Promise; + + dup(): Promise; + + toString(): string; + name(): string; + email(): string; + when(): Time; +} diff --git a/types/stash.d.ts b/types/stash.d.ts new file mode 100644 index 0000000000..20b74d14eb --- /dev/null +++ b/types/stash.d.ts @@ -0,0 +1,46 @@ +import { CheckoutOptions } from "./checkout-options"; +import { Oid } from "./oid"; +import { Repository } from "./repository"; +import { Signature } from "./signature"; + +export namespace Stash { + const enum APPLY_FLAGS { + APPLY_DEFAULT = 0, + APPLY_REINSTATE_INDEX = 1, + } + + const enum APPLY_PROGRESS { + NONE = 0, + LOADING_STASH = 1, + ANALYZE_INDEX = 2, + ANALYZE_MODIFIED = 3, + ANALYZE_UNTRACKED = 4, + CHECKOUT_UNTRACKED = 5, + CHECKOUT_MODIFIED = 6, + DONE = 7, + } + + const enum FLAGS { + DEFAULT = 0, + KEEP_INDEX = 1, + INCLUDE_UNTRACKED = 2, + INCLUDE_IGNORED = 4, + } +} + +export interface StashApplyOptions { + version?: number | undefined; + flags?: number | undefined; + checkoutOptions?: CheckoutOptions | undefined; + progressCb?: Function | undefined; + progressPayload?: any; +} + +export class Stash { + static apply(repo: Repository, index: number, options?: StashApplyOptions): Promise; + static applyInitOptions(opts: StashApplyOptions, version: number): number; + static drop(repo: Repository, index: number): Promise; + static foreach(repo: Repository, callback?: Function): Promise; + static pop(repo: Repository, index: number, options?: StashApplyOptions): Promise; + static save(repo: Repository, stasher: Signature, message: string, flags: number): Promise; +} diff --git a/types/status-entry.d.ts b/types/status-entry.d.ts new file mode 100644 index 0000000000..b63058bff5 --- /dev/null +++ b/types/status-entry.d.ts @@ -0,0 +1,7 @@ +import { DiffDelta } from "./diff-delta"; + +export class StatusEntry { + status(): number; + headToIndex(): DiffDelta; + indexToWorkdir(): DiffDelta; +} diff --git a/types/status-file-options.d.ts b/types/status-file-options.d.ts new file mode 100644 index 0000000000..2503342852 --- /dev/null +++ b/types/status-file-options.d.ts @@ -0,0 +1,8 @@ +import { StatusEntry } from "./status-entry"; + +export interface StatusFileOptions { + path?: string | undefined; + status?: number | undefined; + entry?: StatusEntry | undefined; + [key: string]: any; +} diff --git a/types/status-file.d.ts b/types/status-file.d.ts new file mode 100644 index 0000000000..d51a93f2f0 --- /dev/null +++ b/types/status-file.d.ts @@ -0,0 +1,20 @@ +import { DiffDelta } from "./diff-delta"; +import { StatusFileOptions } from "./status-file-options"; + +export class StatusFile { + constructor(args: StatusFileOptions); + headToIndex(): DiffDelta; + indexToWorkdir(): DiffDelta; + inIndex(): boolean; + inWorkingTree(): boolean; + isConflicted(): boolean; + isDeleted(): boolean; + isIgnored(): boolean; + isModified(): boolean; + isNew(): boolean; + isRenamed(): boolean; + isTypechange(): boolean; + path(): string; + status(): string[]; + statusBit(): number; +} diff --git a/types/status-list.d.ts b/types/status-list.d.ts new file mode 100644 index 0000000000..de05652824 --- /dev/null +++ b/types/status-list.d.ts @@ -0,0 +1,11 @@ +import { DiffPerfdata } from "./diff-perf-data"; +import { Repository } from "./repository"; +import { StatusOptions } from "./status-options"; + +export class StatusList { + static create(repo: Repository, opts?: StatusOptions): Promise; + + entrycount(): number; + + getPerfdata(): Promise; +} diff --git a/types/status-options.d.ts b/types/status-options.d.ts new file mode 100644 index 0000000000..1013992cd5 --- /dev/null +++ b/types/status-options.d.ts @@ -0,0 +1,9 @@ +import { Strarray } from "./str-array"; + +export interface StatusOptions { + version?: number | undefined; + show?: number | undefined; + flags?: number | undefined; + pathspec?: Strarray | string | string[] | undefined; + [key: string]: any; +} diff --git a/types/status.d.ts b/types/status.d.ts new file mode 100644 index 0000000000..0f0c82e51c --- /dev/null +++ b/types/status.d.ts @@ -0,0 +1,56 @@ +import { Repository } from "./repository"; +import { StatusEntry } from "./status-entry"; +import { StatusList } from "./status-list"; +import { StatusOptions } from "./status-options"; + +export namespace Status { + const enum STATUS { + CURRENT = 0, + INDEX_NEW = 1, + INDEX_MODIFIED = 2, + INDEX_DELETED = 4, + INDEX_RENAMED = 8, + INDEX_TYPECHANGE = 16, + WT_NEW = 128, + WT_MODIFIED = 256, + WT_DELETED = 512, + WT_TYPECHANGE = 1024, + WT_RENAMED = 2048, + WT_UNREADABLE = 4096, + IGNORED = 16384, + CONFLICTED = 32768, + } + + const enum OPT { + INCLUDE_UNTRACKED = 1, + INCLUDE_IGNORED = 2, + INCLUDE_UNMODIFIED = 4, + EXCLUDE_SUBMODULES = 8, + RECURSE_UNTRACKED_DIRS = 16, + DISABLE_PATHSPEC_MATCH = 32, + RECURSE_IGNORED_DIRS = 64, + RENAMES_HEAD_TO_INDEX = 128, + RENAMES_INDEX_TO_WORKDIR = 256, + SORT_CASE_SENSITIVELY = 512, + SORT_CASE_INSENSITIVELY = 1024, + RENAMES_FROM_REWRITES = 2048, + NO_REFRESH = 4096, + UPDATE_INDEX = 8192, + INCLUDE_UNREADABLE = 16384, + INCLUDE_UNREADABLE_AS_UNTRACKED = 32768, + } + + const enum SHOW { + INDEX_AND_WORKDIR = 0, + INDEX_ONLY = 1, + WORKDIR_ONLY = 2, + } +} + +export class Status { + static byIndex(statuslist: StatusList, idx: number): StatusEntry; + static file(repo: Repository, path: string): number; + static foreach(repo: Repository, callback?: Function): Promise; + static foreachExt(repo: Repository, opts?: StatusOptions, callback?: Function): Promise; + static shouldIgnore(ignored: number, repo: Repository, path: string): number; +} diff --git a/types/str-array.d.ts b/types/str-array.d.ts new file mode 100644 index 0000000000..4b3694d711 --- /dev/null +++ b/types/str-array.d.ts @@ -0,0 +1,6 @@ +export class Strarray { + copy(src: Strarray): number; + + strings: string[]; + count: number; +} diff --git a/types/submodule-update-options.d.ts b/types/submodule-update-options.d.ts new file mode 100644 index 0000000000..dc9f9c75ad --- /dev/null +++ b/types/submodule-update-options.d.ts @@ -0,0 +1,10 @@ +import { CheckoutOptions } from "./checkout-options"; +import { FetchOptions } from "./fetch-options"; + +export interface SubmoduleUpdateOptions { + version?: number | undefined; + checkoutOpts?: CheckoutOptions | undefined; + fetchOpts?: FetchOptions | undefined; + cloneCheckoutStrategy?: number | undefined; + [key: string]: any; +} diff --git a/types/submodule.d.ts b/types/submodule.d.ts new file mode 100644 index 0000000000..ce52f6ae68 --- /dev/null +++ b/types/submodule.d.ts @@ -0,0 +1,84 @@ +import { Buf } from "./buf"; +import { Oid } from "./oid"; +import { Repository } from "./repository"; +import { SubmoduleUpdateOptions } from "./submodule-update-options"; + +export namespace Submodule { + const enum IGNORE { + UNSPECIFIED = -1, + NONE = 1, + UNTRACKED = 2, + DIRTY = 3, + ALL = 4, + } + + const enum RECURSE { + NO = 0, + YES = 1, + ONDEMAND = 2, + } + + const enum STATUS { + IN_HEAD = 1, + IN_INDEX = 2, + IN_CONFIG = 4, + IN_WD = 8, + INDEX_ADDED = 16, + INDEX_DELETED = 32, + INDEX_MODIFIED = 64, + WD_UNINITIALIZED = 128, + WD_ADDED = 256, + WD_DELETED = 512, + WD_MODIFIED = 1024, + WD_INDEX_MODIFIED = 2048, + WD_WD_MODIFIED = 4096, + WD_UNTRACKED = 8192, + } + + const enum UPDATE { + CHECKOUT = 1, + REBASE = 2, + MERGE = 3, + NONE = 4, + DEFAULT = 0, + } +} + +export class Submodule { + static addSetup(repo: Repository, url: string, path: string, useGitLink: number): Promise; + static foreach(repo: Repository, callback?: Function): Promise; + static lookup(repo: Repository, name: string): Promise; + static resolveUrl(repo: Repository, url: string): Promise; + static setBranch(repo: Repository, name: string, branch: string): number; + static setFetchRecurseSubmodules(repo: Repository, name: string, fetchRecurseSubmodules: number): number; + static setIgnore(repo: Repository, name: string, ignore: number): Promise; + static setUpdate(repo: Repository, name: string, update: number): Promise; + static setUrl(repo: Repository, name: string, url: string): Promise; + static status(repo: Repository, name: string, ignore: number): Promise; + static updateInitOptions(opts: SubmoduleUpdateOptions, version: number): number; + + addFinalize(): Promise; + addToIndex(writeIndex: number): Promise; + branch(): string; + fetchRecurseSubmodules(): number; + + headId(): Oid; + ignore(): number; + indexId(): Oid; + init(overwrite: number): Promise; + location(): Promise; + name(): string; + open(): Promise; + owner(): Repository; + path(): string; + reload(force: number): number; + repoInit(useGitLink: number): Promise; + sync(): Promise; + /** + * Updates a submodule + */ + update(init: number, options?: SubmoduleUpdateOptions): Promise; + updateStrategy(): number; + url(): string; + wdId(): Oid; +} diff --git a/types/tag.d.ts b/types/tag.d.ts new file mode 100644 index 0000000000..59c16e2162 --- /dev/null +++ b/types/tag.d.ts @@ -0,0 +1,58 @@ +import { Error } from "./error"; +import { Object } from "./object"; +import { Oid } from "./oid"; +import { Repository } from "./repository"; +import { Signature } from "./signature"; +import { Strarray } from "./str-array"; + +export class Tag { + static annotationCreate( + repo: Repository, + tagName: string, + target: Object, + tagger: Signature, + message: string, + ): Promise; + static create( + repo: Repository, + tagName: string, + target: Object, + tagger: Signature, + message: string, + force: number, + ): Promise; + static createLightweight(repo: Repository, tagName: string, target: Object, force: number): Promise; + static createWithSignature( + repo: Repository, + tagName: string, + target: Oid | string, + tagger: Signature, + message: string | undefined | null, + force: number, + signingCallback: ( + data: string, + ) => + | Promise<{ code: Error.CODE; field?: string | undefined; signedData: string }> + | { code: Error.CODE; field?: string | undefined; signedData: string }, + ): Promise; + static delete(repo: Repository, tagName: string): Promise; + static list(repo: Repository): Promise; + static listMatch(pattern: string, repo: Repository): Promise; + /** + * Retrieves the tag pointed to by the oid + */ + static lookup(repo: Repository, id: string | Oid | Tag): Promise; + static lookupPrefix(repo: Repository, id: Oid, len: number): Promise; + + dup(): Promise; + + id(): Oid; + message(): string; + name(): string; + owner(): Repository; + peel(tagTargetOut: Object): number; + tagger(): Signature; + target(): Promise; + targetId(): Oid; + targetType(): number; +} diff --git a/types/time.d.ts b/types/time.d.ts new file mode 100644 index 0000000000..cb42ea6838 --- /dev/null +++ b/types/time.d.ts @@ -0,0 +1,4 @@ +export class Time { + time(): number; + offset(): number; +} diff --git a/types/transaction.d.ts b/types/transaction.d.ts new file mode 100644 index 0000000000..cff36ebea9 --- /dev/null +++ b/types/transaction.d.ts @@ -0,0 +1,16 @@ +import { Oid } from "./oid"; +import { Reflog } from "./ref-log"; +import { Repository } from "./repository"; +import { Signature } from "./signature"; + +/** Atomically update multiple references after acquiring their locks. */ +export class Transaction { + static create(repo: Repository): Promise; + + lockRef(refname: string): number; + setTarget(refname: string, target: Oid, signature: Signature | null, message: string | null): number; + setSymbolicTarget(refname: string, target: string, signature: Signature | null, message: string | null): number; + setReflog(refname: string, reflog: Reflog): number; + remove(refname: string): number; + commit(): number; +} diff --git a/types/transfer-progress.d.ts b/types/transfer-progress.d.ts new file mode 100644 index 0000000000..8280f8c6e4 --- /dev/null +++ b/types/transfer-progress.d.ts @@ -0,0 +1,9 @@ +export class TransferProgress { + totalObjects(): number; + indexedObjects(): number; + receivedObjects(): number; + localObjects(): number; + totalDeltas(): number; + indexedDeltas(): number; + receivedBytes(): number; +} diff --git a/types/transport.d.ts b/types/transport.d.ts new file mode 100644 index 0000000000..d463105ede --- /dev/null +++ b/types/transport.d.ts @@ -0,0 +1,16 @@ +import { Cert } from "./cert"; +import { Remote } from "./remote"; +import { Strarray } from "./str-array"; + +export namespace Transport { + const enum FLAGS { + NONE = 0, + } +} + +export class Transport { + static sshWithPaths(owner: Remote, payload: Strarray | string | string[]): Promise; + static unregister(prefix: string): number; + init(version: number): number; + smartCertificateCheck(cert: Cert, valid: number, hostName: string): number; +} diff --git a/types/tree-builder.d.ts b/types/tree-builder.d.ts new file mode 100644 index 0000000000..743eb7b692 --- /dev/null +++ b/types/tree-builder.d.ts @@ -0,0 +1,14 @@ +import { Oid } from "./oid"; +import { Repository } from "./repository"; +import { Tree } from "./tree"; +import { TreeEntry } from "./tree-entry"; + +export class Treebuilder { + static create(repo: Repository, source?: Tree | null): Promise; + clear(): void; + entrycount(): number; + get(filename: string): TreeEntry; + insert(filename: string, id: Oid, filemode: number): Promise; + remove(filename: string): number; + write(): Promise; +} diff --git a/types/tree-entry.d.ts b/types/tree-entry.d.ts new file mode 100644 index 0000000000..6edd93a49f --- /dev/null +++ b/types/tree-entry.d.ts @@ -0,0 +1,47 @@ +import { Blob } from "./blob"; +import { Oid } from "./oid"; +import { Repository } from "./repository"; +import { Tree } from "./tree"; + +export namespace TreeEntry { + const enum FILEMODE { + UNREADABLE = 0, + TREE = 16384, + BLOB = 33188, + EXECUTABLE = 33261, + LINK = 40960, + COMMIT = 57344, + } +} + +export class TreeEntry { + filemode(): TreeEntry.FILEMODE; + filemodeRaw(): TreeEntry.FILEMODE; + getBlob(): Promise; + getTree(): Promise; + id(): Oid; + isBlob(): boolean; + isFile(): boolean; + isTree(): boolean; + isDirectory(): boolean; + isSubmodule(): boolean; + /** + * Retrieve the SHA for this TreeEntry. + */ + sha(): string; + name(): string; + /** + * Retrieve the SHA for this TreeEntry. Alias for sha + */ + oid(): string; + /** + * Returns the path for this entry. + */ + path(): string; + /** + * Alias for path + */ + toString(): string; + toObject(repo: Repository): Object; + type(): number; +} diff --git a/types/tree-update.d.ts b/types/tree-update.d.ts new file mode 100644 index 0000000000..1d94211502 --- /dev/null +++ b/types/tree-update.d.ts @@ -0,0 +1,8 @@ +import { Oid } from "./oid"; + +export class TreeUpdate { + action: number; + filemode: number; + id: Oid; + path: string; +} diff --git a/types/tree.d.ts b/types/tree.d.ts new file mode 100644 index 0000000000..69eb45d2a0 --- /dev/null +++ b/types/tree.d.ts @@ -0,0 +1,77 @@ +import { Diff } from "./diff"; +import { DiffFile } from "./diff-file"; +import { DiffOptions } from "./diff-options"; +import { Oid } from "./oid"; +import { Repository } from "./repository"; +import { Treebuilder } from "./tree-builder"; +import { TreeEntry } from "./tree-entry"; +import { TreeUpdate } from "./tree-update"; + +export namespace Tree { + const enum WALK_MODE { + WALK_PRE = 0, + WALK_POST = 1, + } +} + +export class Tree { + static entryCmp(tree1: TreeEntry, tree2: TreeEntry): number; + static entryDup(dest: TreeEntry, source: TreeEntry): number; + static lookupPrefix(repo: Repository, id: Oid, len: number): Promise; + /** + * Retrieves the tree pointed to by the oid + */ + static lookup(repo: Repository, id: string | Oid | Tree, callback?: Function): Promise; + + entryById(id: Oid): TreeEntry; + _entryByIndex(idx: number): TreeEntry; + /** + * Get an entry by name; if the tree is a directory, the name is the filename. + */ + entryByName(name: string): TreeEntry; + _entryByName(filename: string): TreeEntry; + entryByPath(path: string): Promise; + entryCount(): number; + + id(): Oid; + owner(): Repository; + /** + * Diff two trees + */ + diff(tree: Tree, callback?: Function): Promise; + /** + * Diff two trees with options + */ + diffWithOptions(tree: Tree | null, options?: DiffOptions, callback?: Function): Promise; + /** + * Get an entry at the ith position. + */ + entryByIndex(i: number): TreeEntry; + /** + * Get an entry at a path. Unlike by name, this takes a fully qualified path, like /foo/bar/baz.javascript + */ + getEntry(filePath: string): Promise; + /** + * Return an array of the entries in this tree (excluding its children). + */ + entries(): TreeEntry[]; + /** + * Recursively walk the tree in breadth-first order. Fires an event for each entry. + */ + walk(blobsOnly?: boolean): NodeJS.EventEmitter & { + /** + * Start walking the tree and emitting events. This should be called after event listeners have been attached. + */ + start: () => void; + }; + /** + * Return the path of this tree, like /lib/foo/bar + */ + path(): string; + /** + * Make builder. This is helpful for modifying trees. + */ + builder(): Treebuilder; + dup(): Promise; + createUpdated(repo: Repository, nUpdates: number, updates: TreeUpdate): Promise; +} diff --git a/types/utils.d.ts b/types/utils.d.ts new file mode 100644 index 0000000000..1dadb2abf7 --- /dev/null +++ b/types/utils.d.ts @@ -0,0 +1,15 @@ +import { Oid } from "./oid"; +import { Repository } from "./repository"; + +export const Utils: { + /** Adapt a lookup method to also accept an already-loaded object. */ + lookupWrapper( + objectType: new (...args: any[]) => T, + lookupFunction?: (repo: Repository, id: string | Oid) => Promise, + ): (repo: Repository, id: string | Oid | T, callback?: (error: Error | null, result?: T) => void) => Promise; + /** Shallow-merge own enumerable properties, with later objects taking precedence. */ + shallowClone(source: T): T; + shallowClone(first: T, second: U): T & U; + shallowClone(first: T, second: U, third: V): T & U & V; + shallowClone(...sources: object[]): object; +}; diff --git a/types/worktree-add-options.d.ts b/types/worktree-add-options.d.ts new file mode 100644 index 0000000000..eea6245143 --- /dev/null +++ b/types/worktree-add-options.d.ts @@ -0,0 +1,10 @@ +import { Reference } from "./reference"; + +export interface WorktreeAddOptions { + lock?: number; + /** + * reference to use for the new worktree HEAD + */ + ref?: Reference; + version?: number; +} diff --git a/types/worktree-prune-options.d.ts b/types/worktree-prune-options.d.ts new file mode 100644 index 0000000000..8d1caadc7c --- /dev/null +++ b/types/worktree-prune-options.d.ts @@ -0,0 +1,7 @@ +export interface WorktreePruneOptions { + /** + * A combination of Worktree.PRUNE + */ + flags?: number; + version?: number; +} diff --git a/types/worktree.d.ts b/types/worktree.d.ts new file mode 100644 index 0000000000..f5441a1d93 --- /dev/null +++ b/types/worktree.d.ts @@ -0,0 +1,71 @@ +import { Buf } from "./buf"; +import { Repository } from "./repository"; +import { WorktreeAddOptions } from "./worktree-add-options"; +import { WorktreePruneOptions } from "./worktree-prune-options"; + +export namespace Worktree { + const enum PRUNE { + VALID = 1, + LOCKED = 2, + WORKING_TREE = 4, + } +} + +export class Worktree { + /** + * @param repo - Repository to create working tree for + * @param name - Name of the working tree + * @param path - Path to create working tree at + * @param opts - Options to modify default behavior. May be NULL + */ + static add(repo: Repository, name: string, path: string, opts?: WorktreeAddOptions): Promise; + + /** + * @param repo - the repo to use when listing working trees + */ + static list(repo: Repository): Promise; + + /** + * @param repo - The repository containing worktrees + * @param name - Name of the working tree to look up + */ + static lookup(repo: Repository, name: string): Promise; + + /** + * @param repo - Repository to look up worktree for + */ + static openFromRepository(repo: Repository): Promise; + + /** + * @param reason - Buffer to store reason in. If NULL no reason is stored. + * @returns - 0 when the working tree not locked, a value greater than zero if it is locked, less than zero if there was an error + */ + isLocked(reason?: Buf): number; + + isPrunable(opts: WorktreePruneOptions): number; + + /** + * @param reason - Reason why the working tree is being locked + * @returns - 0 on success, non-zero otherwise + */ + lock(reason: string): number; + + name(): string; + path(): string; + + /** + * @param opts - Specifies which checks to override. See isPrunable. May be NULL + * @returns - 0 or an error code + */ + prune(opts?: WorktreePruneOptions): number; + + /** + * @returns - 0 on success, 1 if worktree was not locked, error-code + */ + unlock(): number; + + /** + * @returns - 0 when worktree is valid, error-code otherwise + */ + validate(): number; +} diff --git a/types/wrapper.d.ts b/types/wrapper.d.ts new file mode 100644 index 0000000000..8982280acf --- /dev/null +++ b/types/wrapper.d.ts @@ -0,0 +1,3 @@ +export class Wrapper { + toBuffer(bufSize: number): Buffer; +}