From d41b27f43335cfb1a8ff49aeb121f992332429cf Mon Sep 17 00:00:00 2001 From: HampusM Date: Thu, 12 Aug 2021 15:37:30 +0200 Subject: Cleaned up the settings implementation & renamed base_dir project-wide to git_dir --- .gitignore | 2 +- docs_src/hacking.md | 8 +++++ docs_src/installation.md | 16 +++++----- packages/client/package.json | 3 +- packages/client/vue.config.js | 5 ++- packages/server/package.json | 1 - packages/server/src/app.ts | 17 ++++++++-- packages/server/src/git/http.ts | 2 +- packages/server/src/git/misc.ts | 6 ++-- packages/server/src/git/repository.ts | 22 ++++++------- packages/server/src/routes/api/v1/index.ts | 4 +-- packages/server/src/routes/api/v1/repo/index.ts | 2 +- packages/server/src/routes/repo.ts | 6 ++-- packages/server/src/server.ts | 42 +++++++------------------ packages/server/src/types/index.d.ts | 7 +++-- test/int/api.int.test.ts | 11 ++++--- test/setup.ts | 10 +++--- test/teardown.ts | 2 +- test/test.env | 2 +- test/unit/blob.unit.test.ts | 4 +-- test/unit/branch.unit.test.ts | 8 ++--- test/unit/commit.unit.test.ts | 2 +- test/unit/diff.unit.test.ts | 2 +- test/unit/misc.unit.test.ts | 8 ++--- test/unit/patch.unit.test.ts | 6 ++-- test/unit/repository.unit.test.ts | 12 +++---- test/unit/tag.unit.test.ts | 4 +-- test/unit/tree.unit.test.ts | 4 +-- test/unit/tree_entry.unit.test.ts | 8 ++--- test/util.ts | 2 +- yarn.lock | 12 ------- 31 files changed, 115 insertions(+), 125 deletions(-) diff --git a/.gitignore b/.gitignore index 5bafb0a..ef9a495 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ .DS_Store node_modules dist -settings.yml +settings.json /coverage /docs diff --git a/docs_src/hacking.md b/docs_src/hacking.md index 81a806c..518477b 100644 --- a/docs_src/hacking.md +++ b/docs_src/hacking.md @@ -14,6 +14,14 @@ This package contains interfaces and types shared by the server and client packa ### Eslint-config-base This package contains a base Eslint configuration for the server and client packages. Aswell as for the test environment. +## Important notes +You may want to add the following to your settings.json +``` +"dev": { + "port": (Port for the Vue.js development server) +} +``` + ## Development utilities You can use the following command to run a live-updating instance of Githermit. diff --git a/docs_src/installation.md b/docs_src/installation.md index 723d35e..f19c4e0 100644 --- a/docs_src/installation.md +++ b/docs_src/installation.md @@ -28,15 +28,15 @@ And finally, build the project. `$ yarn build` -The final step is to create a file called `settings.yml` with the following content. +The final step is to create a file called `settings.json` with the following content. ``` -host: (Host address) -port: (Port) -dev_port: (Port for development server) -production: (Set this to true unless you're doing changes to Githermit) -title: (Title of your Githermit instance) -about: (Short description of your Githermit instance) -base_dir: (Directory where all of your bare Git repositories are located) +{ + "host": "(Host address)", + "port": (Port), + "title": "(Title of your Githermit instance)", + "about": "(Short description of your Githermit instance)", + "git_dir: "(Directory where all of your bare Git repositories are located)" +} ``` ## Starting diff --git a/packages/client/package.json b/packages/client/package.json index 54068d6..f1797e3 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -13,7 +13,6 @@ "core-js": "^3.6.5", "date-fns": "^2.22.1", "highlight.js": "^11.0.1", - "js-yaml": "^4.1.0", "marked": "^2.1.3", "vue": "^3.0.0", "vue-loading-overlay": "^4.0.3", @@ -32,6 +31,7 @@ "@vue/compiler-sfc": "^3.0.0", "@vue/eslint-config-standard": "^6.0.0", "@vue/eslint-config-typescript": "^7.0.0", + "api": "^1.0.0", "eslint": "^7.31.0", "eslint-config-base": "^1.0.0", "eslint-plugin-import": "^2.23.4", @@ -40,7 +40,6 @@ "eslint-plugin-vue": "^7.14.0", "sass": "^1.26.5", "sass-loader": "^12.1.0", - "api": "^1.0.0", "typescript": "^4.3.5", "vue-eslint-parser": "^7.9.0", "webpack": "^5.46.0" diff --git a/packages/client/vue.config.js b/packages/client/vue.config.js index cf7622e..f19863a 100644 --- a/packages/client/vue.config.js +++ b/packages/client/vue.config.js @@ -1,13 +1,12 @@ -const yaml = require("js-yaml"); const fs = require("fs"); const path = require("path"); -const settings = yaml.load(fs.readFileSync(path.join(__dirname, "/../../settings.yml"), "utf8")); +const settings = JSON.parse(fs.readFileSync(path.join(__dirname, "/../../settings.json"), "utf-8")); module.exports = { devServer: { host: settings.host, - port: settings.dev_port, + port: settings.dev.port, proxy: { "^/api": { target: `http://${settings.host}:${settings.port}`, diff --git a/packages/server/package.json b/packages/server/package.json index 8ffb19b..6d213dd 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -12,7 +12,6 @@ "date-fns": "^2.22.1", "fastify": "^3.17.0", "fastify-static": "^4.2.2", - "js-yaml": "^4.1.0", "nodegit": "^0.27.0", "openpgp": "^5.0.0-5", "tar-stream": "^2.2.0", diff --git a/packages/server/src/app.ts b/packages/server/src/app.ts index f52333c..9ca3769 100644 --- a/packages/server/src/app.ts +++ b/packages/server/src/app.ts @@ -3,8 +3,11 @@ import { fastify as fastifyFactory, FastifyInstance } from "fastify"; import fastifyStatic from "fastify-static"; import { Settings } from "./types"; import repo from "./routes/repo"; +import { join } from "path"; +import { readdirSync } from "fs"; +import { exit } from "process"; -export default function buildApp(settings: Settings, dist_dir: string): FastifyInstance { +export default function buildApp(settings: Settings): FastifyInstance { const fastify = fastifyFactory(); fastify.setErrorHandler((err, req, reply) => { @@ -16,7 +19,17 @@ export default function buildApp(settings: Settings, dist_dir: string): FastifyI reply.code(404).send("Page not found!"); }); - if(settings.production) { + if(!settings.dev) { + const dist_dir = join(__dirname, "/../../client/dist"); + + try { + readdirSync(dist_dir); + } + catch { + console.error("Error: Client dist directory doesn't exist!"); + exit(1); + } + fastify.register(fastifyStatic, { root: dist_dir }); fastify.route({ diff --git a/packages/server/src/git/http.ts b/packages/server/src/git/http.ts index 183c6df..3e7e25d 100644 --- a/packages/server/src/git/http.ts +++ b/packages/server/src/git/http.ts @@ -50,7 +50,7 @@ export function connect(repository: Repository, req: Request, reply: FastifyRepl reply.raw.writeHead(200, { "Content-Type": content_type }); - const spawn_args = [ "--stateless-rpc", join(repository.base_dir, repository.name.full) ]; + const spawn_args = [ "--stateless-rpc", join(repository.git_dir, repository.name.full) ]; if(is_discovery) { spawn_args.push("--advertise-refs"); diff --git a/packages/server/src/git/misc.ts b/packages/server/src/git/misc.ts index da9b1ee..1fda304 100644 --- a/packages/server/src/git/misc.ts +++ b/packages/server/src/git/misc.ts @@ -17,13 +17,13 @@ export async function findAsync(arr: T[], callback: (t: T) => Promise { +export function getFile(git_dir: string, repository: string, file: string): Promise { return new Promise((resolve, reject) => { - readFile(`${base_dir}/${repository}/${file}`, (err, content) => { + readFile(`${git_dir}/${repository}/${file}`, (err, content) => { if(err) { reject(createError(MiscError, 500, "Failed to open repository file " + file)); return; diff --git a/packages/server/src/git/repository.ts b/packages/server/src/git/repository.ts index 87c6d3a..63ede23 100644 --- a/packages/server/src/git/repository.ts +++ b/packages/server/src/git/repository.ts @@ -37,7 +37,7 @@ export class Repository { public ng_repository: NodeGitRepository; public name: RepositoryName; - public base_dir: string; + public git_dir: string; public branch_name: string; /** @@ -50,7 +50,7 @@ export class Repository { short: basename(repository.path()).slice(0, -4), full: basename(repository.path()) }; - this.base_dir = dirname(repository.path()); + this.git_dir = dirname(repository.path()); this.branch_name = branch; } @@ -59,14 +59,14 @@ export class Repository { * Returns the repository's description */ public description(): Promise { - return getFile(this.base_dir, this.name.full, "description"); + return getFile(this.git_dir, this.name.full, "description"); } /** * Returns the repository's owner */ public owner(): Promise { - return getFile(this.base_dir, this.name.full, "owner"); + return getFile(this.git_dir, this.name.full, "owner"); } /** @@ -154,13 +154,13 @@ export class Repository { /** * Opens a bare git repository * - * @param base_dir - The directory that contains the repository + * @param git_dir - The directory that contains the repository * @param repository - The directory of a bare repository * @param branch - A branch to use * @returns An instance of a git repository */ - public static async open(base_dir: string, repository: string, branch?: string): Promise { - let ng_repository = await NodeGitRepository.openBare(`${base_dir}/${getFullRepositoryName(repository)}`).catch((err: WeirdError) => { + public static async open(git_dir: string, repository: string, branch?: string): Promise { + let ng_repository = await NodeGitRepository.openBare(`${git_dir}/${getFullRepositoryName(repository)}`).catch((err: WeirdError) => { if(err.errno === -3) { throw(createError(RepositoryError, 404, "Repository not found")); } @@ -180,11 +180,11 @@ export class Repository { /** * Opens all of the git repositories inside a directory * - * @param base_dir - The directory that contains the repositories + * @param git_dir - The directory that contains the repositories * @returns An array of repository instances */ - public static async openAll(base_dir: string): Promise { - const dir_content = await getDirectory(base_dir); + public static async openAll(git_dir: string): Promise { + const dir_content = await getDirectory(git_dir); if(dir_content.length === 0) { return []; @@ -192,6 +192,6 @@ export class Repository { const repositories = dir_content.filter(dir_entry => dir_entry.endsWith(".git")); - return Promise.all(repositories.map(repository => this.open(base_dir, repository))); + return Promise.all(repositories.map(repository => this.open(git_dir, repository))); } } \ No newline at end of file diff --git a/packages/server/src/routes/api/v1/index.ts b/packages/server/src/routes/api/v1/index.ts index 9c35d53..1adb3cb 100644 --- a/packages/server/src/routes/api/v1/index.ts +++ b/packages/server/src/routes/api/v1/index.ts @@ -21,7 +21,7 @@ function reposEndpoints(fastify: FastifyInstance, opts: FastifyPluginOptions, do method: "GET", url: "/repos", handler: async(req, reply) => { - const repos = await Repository.openAll(opts.config.settings.base_dir); + const repos = await Repository.openAll(opts.config.settings.git_dir); if(!repos) { reply.send({ data: [] }); @@ -49,7 +49,7 @@ function reposEndpoints(fastify: FastifyInstance, opts: FastifyPluginOptions, do return; } - const repository: Repository | BaseError = await Repository.open(opts.config.settings.base_dir, req.params.repo).catch(err => err); + const repository: Repository | BaseError = await Repository.open(opts.config.settings.git_dir, req.params.repo).catch(err => err); if(repository instanceof BaseError) { reply.code(repository.code).send({ error: repository.message }); diff --git a/packages/server/src/routes/api/v1/repo/index.ts b/packages/server/src/routes/api/v1/repo/index.ts index b1b1030..bcd2e5c 100644 --- a/packages/server/src/routes/api/v1/repo/index.ts +++ b/packages/server/src/routes/api/v1/repo/index.ts @@ -19,7 +19,7 @@ declare module "fastify" { function addHooks(fastify: FastifyInstance, opts: FastifyPluginOptions): void { fastify.addHook("preHandler", async(req: CoolFastifyRequest, reply) => { - const repository = await Repository.open(opts.config.settings.base_dir, req.params.repo, req.query.branch).catch((err: BaseError) => err); + const repository = await Repository.open(opts.config.settings.git_dir, req.params.repo, req.query.branch).catch((err: BaseError) => err); if(repository instanceof BaseError) { reply.code(repository.code).send({ error: repository.message }); diff --git a/packages/server/src/routes/repo.ts b/packages/server/src/routes/repo.ts index 99c2295..43d89d2 100644 --- a/packages/server/src/routes/repo.ts +++ b/packages/server/src/routes/repo.ts @@ -35,7 +35,7 @@ export default function(fastify: FastifyInstance, opts: FastifyPluginOptions, do return; } - const repository = await Repository.open(opts.config.settings.base_dir, req.params.repo); + const repository = await Repository.open(opts.config.settings.git_dir, req.params.repo); repository.HTTPconnect(req, reply); } }); @@ -44,7 +44,7 @@ export default function(fastify: FastifyInstance, opts: FastifyPluginOptions, do method: "POST", url: "/git-upload-pack", handler: async(req, reply) => { - const repository = await Repository.open(opts.config.settings.base_dir, req.params.repo); + const repository = await Repository.open(opts.config.settings.git_dir, req.params.repo); repository.HTTPconnect(req, reply); } }); @@ -62,7 +62,7 @@ export default function(fastify: FastifyInstance, opts: FastifyPluginOptions, do method: "GET", url: "/refs/tags/:tag", handler: async(req, reply) => { - const repository = await Repository.open(opts.config.settings.base_dir, req.params.repo).catch((err: BaseError) => err); + const repository = await Repository.open(opts.config.settings.git_dir, req.params.repo).catch((err: BaseError) => err); if(repository instanceof BaseError) { reply.code(repository.code).send(repository.message); diff --git a/packages/server/src/server.ts b/packages/server/src/server.ts index 15f902c..11b3f7f 100644 --- a/packages/server/src/server.ts +++ b/packages/server/src/server.ts @@ -1,53 +1,35 @@ import { readFileSync, readdirSync } from "fs"; import { join } from "path"; -import { load } from "js-yaml"; import { exit } from "process"; import { Settings } from "./types"; import buildApp from "./app"; -const settings = load(readFileSync(join(__dirname, "/../../../settings.yml"), "utf8")) as Settings; +const settings = JSON.parse(readFileSync(join(__dirname, "/../../../settings.json"), "utf-8")) as Settings; + const settings_keys = Object.keys(settings); -const mandatory_settings = [ "host", "port", "dev_port", "title", "about", "base_dir", "production" ]; +const mandatory_settings = [ "host", "port", "title", "about", "git_dir" ]; -// Make sure that all the required settings are present +// Get missing mandatory settings const settings_not_included = mandatory_settings.filter(x => !settings_keys.includes(x)); + +// Error out and exit if there's any missing settings if(settings_not_included.length !== 0) { - console.log(`Error: settings.yml is missing ${(settings_not_included.length > 1) ? "keys" : "key"}:`); + console.log(`Error: settings file is missing ${(settings_not_included.length > 1) ? "keys" : "key"}:`); console.log(settings_not_included.join(", ")); exit(1); } -// Make sure that there's not an excessive amount of settings -const mandatory_not_included = settings_keys.filter(x => !mandatory_settings.includes(x)); -if(mandatory_not_included.length !== 0) { - console.log(`Error: settings.yml includes ${(mandatory_not_included.length > 1) ? "pointless keys" : "a pointless key"}:`); - console.log(mandatory_not_included.join(", ")); - exit(1); -} - -// Make sure that the base directory specified in the settings actually exists +// Make sure that the git directory specified in the settings actually exists try { - readdirSync(settings.base_dir); + readdirSync(settings.git_dir); } catch { - console.error(`Error: Tried opening the base directory. No such directory: ${settings.base_dir}`); + console.error(`Error: Git directory ${settings.git_dir} doesn't exist!`); exit(1); } -const dist_dir = join(__dirname, "/../../client/dist"); - -if(settings.production) { - try { - readdirSync(dist_dir); - } - catch { - console.error("Error: Tried opening the dist directory but it doesn't exist.\nDid you accidentally turn on the production setting?"); - exit(1); - } -} - -const app = buildApp(settings, dist_dir); +const app = buildApp(settings); app.listen(settings.port, settings.host, (err: Error, addr: string) => { if(err) { @@ -55,5 +37,5 @@ app.listen(settings.port, settings.host, (err: Error, addr: string) => { exit(1); } - console.log(`App is running on ${addr}`); + console.log(`Githermit is running on ${addr}`); }); \ No newline at end of file diff --git a/packages/server/src/types/index.d.ts b/packages/server/src/types/index.d.ts index beb5f49..8f592f9 100644 --- a/packages/server/src/types/index.d.ts +++ b/packages/server/src/types/index.d.ts @@ -1,9 +1,10 @@ export type Settings = { host: string, port: number, - dev_port: number, title: string, about: string, - base_dir: string, - production: boolean + git_dir: string, + dev: { + port: number + } } \ No newline at end of file diff --git a/test/int/api.int.test.ts b/test/int/api.int.test.ts index 202aa88..70cf263 100644 --- a/test/int/api.int.test.ts +++ b/test/int/api.int.test.ts @@ -19,12 +19,13 @@ describe("API", () => { app = buildApp({ host: host, port: port, - dev_port: 0, title: "Bob's cool projects", about: "All of my personal projects. Completely FOSS.", - base_dir: env.BASE_DIR, - production: false - }, ""); + git_dir: env.GIT_DIR, + dev: { + port: 0 + } + }); await app.listen(port); @@ -265,7 +266,7 @@ describe("API", () => { beforeAll(async() => { const body = new Readable({ read: () => null }); - let head = (await readFile(`${env.BASE_DIR}/${env.AVAIL_REPO}/FETCH_HEAD`)).toString(); + let head = (await readFile(`${env.GIT_DIR}/${env.AVAIL_REPO}/FETCH_HEAD`)).toString(); const find_head = /^[a-f0-9]+/.exec(head); diff --git a/test/setup.ts b/test/setup.ts index d446296..764c07a 100644 --- a/test/setup.ts +++ b/test/setup.ts @@ -8,17 +8,17 @@ config({ path: "test/test.env" }); const env = process.env as EnvironmentVariables; export default async function(): Promise { - const can_access = await access(env.BASE_DIR) + const can_access = await access(env.GIT_DIR) .then(() => true) .catch(() => false); if(can_access) { - await remove(env.BASE_DIR); + await remove(env.GIT_DIR); } - await mkdir(env.BASE_DIR); + await mkdir(env.GIT_DIR); - const repository = await Clone.clone(env.AVAIL_REPO_URL, `${env.BASE_DIR}/${env.AVAIL_REPO}`, { bare: 1 }); + const repository = await Clone.clone(env.AVAIL_REPO_URL, `${env.GIT_DIR}/${env.AVAIL_REPO}`, { bare: 1 }); const config = await repository.config(); await config.setString("user.name", "BobDylan"); @@ -27,5 +27,5 @@ export default async function(): Promise { await repository.fetchAll(); await repository.createTag((await repository.getMasterCommit()).id(), "1.2", "Fixed stuff"); - await writeFile(`${env.BASE_DIR}/${env.AVAIL_REPO}/owner`, "Bob"); + await writeFile(`${env.GIT_DIR}/${env.AVAIL_REPO}/owner`, "Bob"); } \ No newline at end of file diff --git a/test/teardown.ts b/test/teardown.ts index c5b49e3..a78bede 100644 --- a/test/teardown.ts +++ b/test/teardown.ts @@ -4,5 +4,5 @@ import { EnvironmentVariables } from "./util"; const env = process.env as EnvironmentVariables; export default async function(): Promise { - await remove(env.BASE_DIR); + await remove(env.GIT_DIR); } \ No newline at end of file diff --git a/test/test.env b/test/test.env index 3017693..98c7588 100644 --- a/test/test.env +++ b/test/test.env @@ -1,4 +1,4 @@ -BASE_DIR=/tmp/githermit_test +GIT_DIR=/tmp/githermit_test AVAIL_REPO=githermit.git AVAIL_REPO_URL=https://gitlab.com/HampusMat/githermit.git UNAVAIL_REPO=angular diff --git a/test/unit/blob.unit.test.ts b/test/unit/blob.unit.test.ts index 1771255..308245a 100644 --- a/test/unit/blob.unit.test.ts +++ b/test/unit/blob.unit.test.ts @@ -10,7 +10,7 @@ describe("Blob", () => { it("Should the get a blob from a path in a tree", async() => { expect.assertions(2); - const tree = await Tree.ofRepository(await Repository.open(env.BASE_DIR, env.AVAIL_REPO)); + const tree = await Tree.ofRepository(await Repository.open(env.GIT_DIR, env.AVAIL_REPO)); const blob = await Blob.fromPath(tree, "packages/client/src/main.ts"); expect(blob).toBeDefined(); @@ -22,7 +22,7 @@ describe("Blob", () => { let blob: Blob; beforeAll(async() => { - const tree = await Tree.ofRepository(await Repository.open(env.BASE_DIR, env.AVAIL_REPO)); + const tree = await Tree.ofRepository(await Repository.open(env.GIT_DIR, env.AVAIL_REPO)); blob = await Blob.fromPath(tree, "packages/client/src/main.ts"); }); diff --git a/test/unit/branch.unit.test.ts b/test/unit/branch.unit.test.ts index 3f067a8..cf37fb5 100644 --- a/test/unit/branch.unit.test.ts +++ b/test/unit/branch.unit.test.ts @@ -9,7 +9,7 @@ describe("Branch", () => { it("Should lookup a branch", async() => { expect.assertions(2); - const repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO); + const repository = await Repository.open(env.GIT_DIR, env.AVAIL_REPO); const branch = await Branch.lookup(repository, "master"); expect(branch).toBeDefined(); @@ -19,7 +19,7 @@ describe("Branch", () => { it("Should lookup if an existent branch exists and respond true", async() => { expect.assertions(2); - const repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO); + const repository = await Repository.open(env.GIT_DIR, env.AVAIL_REPO); const branch_exists = await Branch.lookupExists(repository.ng_repository, "master"); expect(branch_exists).toBeDefined(); @@ -29,7 +29,7 @@ describe("Branch", () => { it("Should lookup if an nonexistent branch exists and respond false", async() => { expect.assertions(2); - const repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO); + const repository = await Repository.open(env.GIT_DIR, env.AVAIL_REPO); const branch_exists = await Branch.lookupExists(repository.ng_repository, "wubbalubbadubdub"); expect(branch_exists).toBeDefined(); @@ -41,7 +41,7 @@ describe("Branch", () => { let branch: Branch; beforeAll(async() => { - const repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO); + const repository = await Repository.open(env.GIT_DIR, env.AVAIL_REPO); branch = await Branch.lookup(repository, "master"); }); diff --git a/test/unit/commit.unit.test.ts b/test/unit/commit.unit.test.ts index e9e0e0d..21c04db 100644 --- a/test/unit/commit.unit.test.ts +++ b/test/unit/commit.unit.test.ts @@ -10,7 +10,7 @@ describe("Commit", () => { let repository: Repository; beforeAll(async() => { - repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO); + repository = await Repository.open(env.GIT_DIR, env.AVAIL_REPO); }); describe("Class methods", () => { diff --git a/test/unit/diff.unit.test.ts b/test/unit/diff.unit.test.ts index ed4061b..2f88d29 100644 --- a/test/unit/diff.unit.test.ts +++ b/test/unit/diff.unit.test.ts @@ -9,7 +9,7 @@ describe("Diff", () => { let diff: Diff; beforeAll(async() => { - const repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO); + const repository = await Repository.open(env.GIT_DIR, env.AVAIL_REPO); diff = await (await repository.head()).diff(); }); diff --git a/test/unit/misc.unit.test.ts b/test/unit/misc.unit.test.ts index c45d8ba..38c69fd 100644 --- a/test/unit/misc.unit.test.ts +++ b/test/unit/misc.unit.test.ts @@ -44,7 +44,7 @@ describe("Miscellaneous functions", () => { it("Should return the content of a file in a bare git repository", async() => { expect.assertions(2); - const content = await getFile(env.BASE_DIR, env.AVAIL_REPO, "description"); + const content = await getFile(env.GIT_DIR, env.AVAIL_REPO, "description"); expect(content).toBeDefined(); expect(content).toEqual("Unnamed repository; edit this file 'description' to name the repository."); @@ -53,7 +53,7 @@ describe("Miscellaneous functions", () => { it("Should fail to return the content of a nonexistent file in a bare repository", async() => { expect.assertions(1); - await expect(getFile(env.BASE_DIR, env.AVAIL_REPO, "myselfasteem")).rejects.toBeInstanceOf(BaseError); + await expect(getFile(env.GIT_DIR, env.AVAIL_REPO, "myselfasteem")).rejects.toBeInstanceOf(BaseError); }); }); @@ -61,7 +61,7 @@ describe("Miscellaneous functions", () => { it("Should return the content of a directory", async() => { expect.assertions(3); - const dir = await getDirectory(`${env.BASE_DIR}/${env.AVAIL_REPO}/refs`); + const dir = await getDirectory(`${env.GIT_DIR}/${env.AVAIL_REPO}/refs`); expect(dir).toBeDefined(); expect(dir).toContain("heads"); @@ -71,7 +71,7 @@ describe("Miscellaneous functions", () => { it("Should fail to return the content of a nonexistent directory", async() => { expect.assertions(1); - await expect(getDirectory(`${env.BASE_DIR}/${env.AVAIL_REPO}/something`)).rejects.toBeInstanceOf(BaseError); + await expect(getDirectory(`${env.GIT_DIR}/${env.AVAIL_REPO}/something`)).rejects.toBeInstanceOf(BaseError); }); }); }); \ No newline at end of file diff --git a/test/unit/patch.unit.test.ts b/test/unit/patch.unit.test.ts index 3197059..d011825 100644 --- a/test/unit/patch.unit.test.ts +++ b/test/unit/patch.unit.test.ts @@ -10,7 +10,7 @@ describe("Patch", () => { it("Should get a patch from a diff", async() => { expect.assertions(2); - const repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO); + const repository = await Repository.open(env.GIT_DIR, env.AVAIL_REPO); const commit = await Commit.lookup(repository, "d856031c58e26992f3e0a481084a190a50b0bcf7"); const patch = await Patch.fromDiff(await commit.diff(), 1); @@ -22,7 +22,7 @@ describe("Patch", () => { it("Should get all patches from a diff", async() => { expect.hasAssertions(); - const repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO); + const repository = await Repository.open(env.GIT_DIR, env.AVAIL_REPO); const commit = await Commit.lookup(repository, "7b3292af22a0496007e974b65cd2e34521c9c429"); const patches = await Patch.allFromDiff(await commit.diff()); @@ -42,7 +42,7 @@ describe("Patch", () => { let patch: Patch; beforeAll(async() => { - repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO); + repository = await Repository.open(env.GIT_DIR, env.AVAIL_REPO); const commit = await Commit.lookup(repository, "7b3292af22a0496007e974b65cd2e34521c9c429"); patch = await Patch.fromDiff(await commit.diff(), 4); diff --git a/test/unit/repository.unit.test.ts b/test/unit/repository.unit.test.ts index 66e32d4..b3d9a2d 100644 --- a/test/unit/repository.unit.test.ts +++ b/test/unit/repository.unit.test.ts @@ -9,7 +9,7 @@ import { BaseError } from "server/src/git/error"; const env = process.env as EnvironmentVariables; function expectRepositoryProperties(repository: Repository) { - expect(repository).toHaveProperty("base_dir"); + expect(repository).toHaveProperty("git_dir"); expect(repository).toHaveProperty("description"); expect(repository).toHaveProperty("name"); expect(repository).toHaveProperty("name.full"); @@ -22,7 +22,7 @@ describe("Repository", () => { it("Should open a repository", async() => { expect.assertions(8); - const repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO); + const repository = await Repository.open(env.GIT_DIR, env.AVAIL_REPO); expect(repository).toBeDefined(); expect(repository).toBeInstanceOf(Repository); @@ -33,19 +33,19 @@ describe("Repository", () => { it("Should fail to open a nonexistant repository", async() => { expect.assertions(1); - await expect(Repository.open(env.BASE_DIR, env.UNAVAIL_REPO)).rejects.toBeInstanceOf(BaseError); + await expect(Repository.open(env.GIT_DIR, env.UNAVAIL_REPO)).rejects.toBeInstanceOf(BaseError); }); it("Should fail to open a repository with a nonexistant branch", async() => { expect.assertions(1); - await expect(Repository.open(env.BASE_DIR, env.AVAIL_REPO, "wubbalubbadubdub")).rejects.toBeInstanceOf(BaseError); + await expect(Repository.open(env.GIT_DIR, env.AVAIL_REPO, "wubbalubbadubdub")).rejects.toBeInstanceOf(BaseError); }); it("Should open all repositories", async() => { expect.hasAssertions(); - const all_repositories = await Repository.openAll(env.BASE_DIR); + const all_repositories = await Repository.openAll(env.GIT_DIR); expect(all_repositories).toBeDefined(); @@ -62,7 +62,7 @@ describe("Repository", () => { let repository: Repository; beforeAll(async() => { - repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO); + repository = await Repository.open(env.GIT_DIR, env.AVAIL_REPO); }); it("Should get the description", async() => { diff --git a/test/unit/tag.unit.test.ts b/test/unit/tag.unit.test.ts index 8321092..76abc33 100644 --- a/test/unit/tag.unit.test.ts +++ b/test/unit/tag.unit.test.ts @@ -9,7 +9,7 @@ describe("Tag", () => { it("Should lookup a tag", async() => { expect.assertions(2); - const repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO); + const repository = await Repository.open(env.GIT_DIR, env.AVAIL_REPO); const tag = await Tag.lookup(repository, "1.2"); @@ -22,7 +22,7 @@ describe("Tag", () => { let tag: Tag; beforeAll(async() => { - const repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO); + const repository = await Repository.open(env.GIT_DIR, env.AVAIL_REPO); tag = await Tag.lookup(repository, "1.2"); }); diff --git a/test/unit/tree.unit.test.ts b/test/unit/tree.unit.test.ts index 1cbc85a..1754e7a 100644 --- a/test/unit/tree.unit.test.ts +++ b/test/unit/tree.unit.test.ts @@ -12,7 +12,7 @@ describe("Tree", () => { it("Should get the tree of a repository", async() => { expect.assertions(2); - const tree = await Tree.ofRepository(await Repository.open(env.BASE_DIR, env.AVAIL_REPO)); + const tree = await Tree.ofRepository(await Repository.open(env.GIT_DIR, env.AVAIL_REPO)); expect(tree).toBeDefined(); expect(tree).toBeInstanceOf(Tree); @@ -23,7 +23,7 @@ describe("Tree", () => { let tree: Tree; beforeAll(async() => { - tree = await Tree.ofRepository(await Repository.open(env.BASE_DIR, env.AVAIL_REPO)); + tree = await Tree.ofRepository(await Repository.open(env.GIT_DIR, env.AVAIL_REPO)); }); it("Should get the entries", () => { diff --git a/test/unit/tree_entry.unit.test.ts b/test/unit/tree_entry.unit.test.ts index de270c5..ca4fbc6 100644 --- a/test/unit/tree_entry.unit.test.ts +++ b/test/unit/tree_entry.unit.test.ts @@ -13,7 +13,7 @@ describe("Tree entry", () => { let tree_entry: BaseTreeEntry; beforeAll(async() => { - const repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO); + const repository = await Repository.open(env.GIT_DIR, env.AVAIL_REPO); const tree = await repository.tree(); tree_entry = tree.entries()[0]; }); @@ -63,7 +63,7 @@ describe("Tree entry", () => { let tree_entry: BaseTreeEntry; beforeAll(async() => { - const repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO); + const repository = await Repository.open(env.GIT_DIR, env.AVAIL_REPO); const tree = await repository.tree(); const entry = tree.entries().find(entry => entry.path === "test"); if(!entry) { @@ -91,7 +91,7 @@ describe("Tree entry", () => { let tree_entry: BaseTreeEntry; beforeAll(async() => { - const repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO); + const repository = await Repository.open(env.GIT_DIR, env.AVAIL_REPO); const tree = await repository.tree(); tree_entry = tree.entries()[0]; }); @@ -108,4 +108,4 @@ describe("Tree entry", () => { }); }); }); -}); +}); \ No newline at end of file diff --git a/test/util.ts b/test/util.ts index 0079580..30a5c60 100644 --- a/test/util.ts +++ b/test/util.ts @@ -1,7 +1,7 @@ import { Commit, CommitAuthor } from "server/src/git/commit"; export type EnvironmentVariables = { - BASE_DIR: string, + GIT_DIR: string, AVAIL_REPO: string, AVAIL_REPO_URL: string, UNAVAIL_REPO: string, diff --git a/yarn.lock b/yarn.lock index 2b3d1c0..4f01e6e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2608,11 +2608,6 @@ argparse@^1.0.7: dependencies: sprintf-js "~1.0.2" -argparse@^2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/argparse/-/argparse-2.0.1.tgz#246f50f3ca78a3240f6c997e8a9bd1eac49e4b38" - integrity sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q== - arr-diff@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/arr-diff/-/arr-diff-4.0.0.tgz#d6461074febfec71e7e15235761a329a5dc7c520" @@ -6909,13 +6904,6 @@ js-yaml@^3.13.1: argparse "^1.0.7" esprima "^4.0.0" -js-yaml@^4.1.0: - version "4.1.0" - resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-4.1.0.tgz#c1fb65f8f5017901cdd2c951864ba18458a10602" - integrity sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA== - dependencies: - argparse "^2.0.1" - jsbn@~0.1.0: version "0.1.1" resolved "https://registry.yarnpkg.com/jsbn/-/jsbn-0.1.1.tgz#a5e654c2e5a2deb5f201d96cefbca80c0ef2f513" -- cgit v1.2.3-18-g5258