Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implment blob and related features #59

Merged
merged 1 commit into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ name: CI
env:
DEBUG: napi:*
APP_NAME: simple-git
MACOSX_DEPLOYMENT_TARGET: '10.13'
MACOSX_DEPLOYMENT_TARGET: "10.13"
permissions:
contents: write
id-token: write
'on':
"on":
push:
branches:
- main
tags-ignore:
- '**'
- "**"
paths-ignore:
- '**/*.md'
- "**/*.md"
- LICENSE
- '**/*.gitignore'
- "**/*.gitignore"
- .editorconfig
- docs/**
pull_request: null
Expand Down Expand Up @@ -120,10 +120,10 @@ jobs:
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
.cargo-cache
target
~/.cargo/registry
~/.cargo/git
.cargo-cache
target
key: ${{ matrix.settings.target }}-cargo-cache
- name: Setup toolchain
run: ${{ matrix.settings.setup }}
Expand All @@ -140,7 +140,7 @@ jobs:
if: ${{ matrix.settings.docker }}
with:
image: ${{ matrix.settings.docker }}
options: '-v ${{ github.workspace }}/.cargo-cache/git:/usr/local/cargo/git -v ${{ github.workspace }}/.cargo-cache/registry:/usr/local/cargo/registry -v ${{ github.workspace }}:/build -w /build'
options: "-v ${{ github.workspace }}/.cargo-cache/git:/usr/local/cargo/git -v ${{ github.workspace }}/.cargo-cache/registry:/usr/local/cargo/registry -v ${{ github.workspace }}:/build -w /build"
run: ${{ matrix.settings.build }}
- name: Build
run: ${{ matrix.settings.build }}
Expand All @@ -166,10 +166,10 @@ jobs:
RUSTUP_IO_THREADS: 1
with:
operating_system: freebsd
version: '14.0'
version: "14.1"
memory: 8G
cpu_count: 3
environment_variables: 'DEBUG RUSTUP_IO_THREADS'
environment_variables: "DEBUG RUSTUP_IO_THREADS"
shell: bash
run: |
sudo pkg install -y -f curl node libnghttp2 npm perl5
Expand Down Expand Up @@ -206,17 +206,17 @@ jobs:
matrix:
settings:
- host: macos-latest
target: 'x86_64-apple-darwin'
architecture: 'x64'
target: "x86_64-apple-darwin"
architecture: "x64"
- host: macos-latest
target: 'aarch64-apple-darwin'
architecture: 'arm64'
target: "aarch64-apple-darwin"
architecture: "arm64"
- host: windows-latest
target: x86_64-pc-windows-msvc
architecture: 'x64'
architecture: "x64"
node:
- '18'
- '20'
- "18"
- "20"
runs-on: ${{ matrix.settings.host }}
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -248,8 +248,8 @@ jobs:
fail-fast: false
matrix:
node:
- '18'
- '20'
- "18"
- "20"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
69 changes: 44 additions & 25 deletions __test__/repo.spec.mjs
Original file line number Diff line number Diff line change
@@ -1,47 +1,66 @@
import { execSync } from 'child_process'
import { join } from 'path'
import { fileURLToPath } from 'url'
import { readFile } from "node:fs/promises";
import { execSync } from "node:child_process";
import { join } from "node:path";
import { fileURLToPath } from "node:url";

import test from 'ava'
import test from "ava";

const __dirname = join(fileURLToPath(import.meta.url), '..')
const __dirname = join(fileURLToPath(import.meta.url), "..");

import { Repository } from '../index.js'
import { Repository } from "../index.js";

const workDir = join(__dirname, '..')
const workDir = join(__dirname, "..");

test.beforeEach((t) => {
t.context.repo = new Repository(workDir)
})
t.context.repo = new Repository(workDir);
});

test('Date should be equal with cli', (t) => {
const { repo } = t.context
test("Date should be equal with cli", (t) => {
const { repo } = t.context;
if (process.env.CI) {
t.notThrows(() => repo.getFileLatestModifiedDate(join('src', 'lib.rs')))
t.notThrows(() => repo.getFileLatestModifiedDate(join("src", "lib.rs")));
} else {
t.deepEqual(
new Date(
execSync('git log -1 --format=%cd --date=iso src/lib.rs', {
execSync("git log -1 --format=%cd --date=iso src/lib.rs", {
cwd: workDir,
})
.toString('utf8')
.trim()
.toString("utf8")
.trim(),
).valueOf(),
repo.getFileLatestModifiedDate(join('src', 'lib.rs'))
)
repo.getFileLatestModifiedDate(join("src", "lib.rs")),
);
}
})
});

test('Should be able to resolve head', (t) => {
const { repo } = t.context
test("Should be able to resolve head", (t) => {
const { repo } = t.context;
t.is(
repo.head().target(),
process.env.CI
? process.env.GITHUB_SHA
: execSync('git rev-parse HEAD', {
: execSync("git rev-parse HEAD", {
cwd: workDir,
})
.toString('utf8')
.trim()
)
})
.toString("utf8")
.trim(),
);
});

test("Should be able to get blob content", async (t) => {
if (process.platform === "win32") {
t.pass("Skip test on windows");
return;
}
const { repo } = t.context;
const blob = repo
.head()
.peelToTree()
.getPath("__test__/repo.spec.mjs")
.toObject(repo)
.peelToBlob();
t.deepEqual(
await readFile(join(__dirname, "repo.spec.mjs"), "utf8"),
Buffer.from(blob.content()).toString("utf8"),
);
});
Loading