Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/cold-moments-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"simple-git": minor
---

Use `pathspec` wrappers for remote and local paths wehn running either `git.clone` or `git.mirror`
5 changes: 5 additions & 0 deletions .changeset/heavy-showers-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"simple-git": patch
---

Restrict lint and format settings with biome.
7 changes: 7 additions & 0 deletions .changeset/shaky-readers-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"simple-git": patch
---

Enhanced `git -c` checks in `unsafe` plugin.

Thanks to @JohannesLks for identifying the issue
44 changes: 27 additions & 17 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,20 @@
"assist": {
"actions": {
"source": {
"organizeImports": "off"
"organizeImports": {
"level": "on",
"options": {
"groups": [
":URL:",
":NODE:",
":BLANK_LINE:",
[":PACKAGE:", ":PACKAGE_WITH_PROTOCOL:"],
":BLANK_LINE:",
":ALIAS:",
":PATH:"
]
}
}
}
}
},
Expand Down Expand Up @@ -51,7 +64,6 @@
"linter": {
"rules": {
"complexity": {
"noBannedTypes": "off",
"noUselessEscapeInRegex": "off",
"useArrowFunction": "off",
"useOptionalChain": "off"
Expand All @@ -60,10 +72,8 @@
"noUnusedPrivateClassMembers": "off"
},
"style": {
"useConst": "off",
"useShorthandFunctionType": "off",
"useTemplate": "off",
"useImportType": "off",
"useNodejsImportProtocol": "off"
},
"suspicious": {
Expand All @@ -76,10 +86,18 @@
},
{
"includes": ["simple-git/src/git.js", "simple-git/scripts/*"],
"assist": {
"actions": {
"source": {
"organizeImports": "off"
}
}
},
"linter": {
"rules": {
"complexity": {
"useArrowFunction": "off"
"useArrowFunction": "off",
"noBannedTypes": "off"
},
"correctness": {
"noUnusedFunctionParameters": "off",
Expand All @@ -95,25 +113,16 @@
"**/__fixtures__/**",
"**/__mocks__/**"
],
"assist": {
"actions": {
"source": {
"organizeImports": "off"
}
}
},
"formatter": {
"enabled": false
},
"linter": {
"rules": {
"complexity": {
"noBannedTypes": "off",
"useArrowFunction": "off"
"useArrowFunction": "off",
"noBannedTypes": "off"
},
"style": {
"useConst": "off",
"useImportType": "off",
"useTemplate": "off"
},
"suspicious": {
Expand All @@ -134,7 +143,8 @@
"!**/coverage/**",
"!**/dist/**",
"!.changeset/**",
"!node_modules/**"
"!node_modules/**",
"!**/.astro/**"
]
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { simpleGit, CleanOptions, SimpleGit, TaskConfigurationError } from 'simple-git';
import { CleanOptions, type SimpleGit, simpleGit, TaskConfigurationError } from 'simple-git';

describe('simple-git', () => {
describe('named export', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import simpleGit, { gitP, CleanOptions, SimpleGit, TaskConfigurationError } from 'simple-git';
import simpleGit, { CleanOptions, gitP, type SimpleGit, TaskConfigurationError } from 'simple-git';

describe('simple-git', () => {
describe('default export', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { default as simpleGit, CleanOptions, SimpleGit, TaskConfigurationError } from 'simple-git';
import { CleanOptions, type SimpleGit, default as simpleGit, TaskConfigurationError } from 'simple-git';

describe('simple-git', () => {
describe('renamed default export', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { simpleGit, CleanOptions, SimpleGit, TaskConfigurationError } from 'simple-git';
import { CleanOptions, type SimpleGit, simpleGit, TaskConfigurationError } from 'simple-git';

describe('simple-git', () => {
describe('named export', () => {
Expand Down
5 changes: 2 additions & 3 deletions packages/test-utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ export * from './src/create-test-context';
export * from './src/expectations';
export * from './src/instance';
export * from './src/like';
export * from './src/wait';

export * from './src/setup/setup-conflicted';
export * from './src/setup/setup-files';
export * from './src/setup/setup-init';
export * from './src/setup/setup-ignored';
export * from './src/setup/setup-init';
export * from './src/wait';
4 changes: 2 additions & 2 deletions packages/test-utils/src/create-test-context.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { existsSync, mkdir, mkdtemp, realpathSync, writeFile, WriteFileOptions } from 'fs';
import { existsSync, mkdir, mkdtemp, realpathSync, type WriteFileOptions, writeFile } from 'fs';

import { simpleGit, SimpleGit } from 'simple-git';
import { type SimpleGit, simpleGit } from 'simple-git';

export interface SimpleGitTestContext {
/** Creates a directory under the repo root at the given path(s) */
Expand Down
2 changes: 1 addition & 1 deletion packages/test-utils/src/setup/setup-conflicted.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SimpleGitTestContext } from '../create-test-context';
import type { SimpleGitTestContext } from '../create-test-context';

export const FIRST_BRANCH = 'first';
export const SECOND_BRANCH = 'second';
Expand Down
2 changes: 1 addition & 1 deletion packages/test-utils/src/setup/setup-files.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SimpleGitTestContext } from '../create-test-context';
import type { SimpleGitTestContext } from '../create-test-context';

export async function setUpFilesAdded(
{ git, files }: SimpleGitTestContext,
Expand Down
2 changes: 1 addition & 1 deletion packages/test-utils/src/setup/setup-ignored.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SimpleGitTestContext } from '../create-test-context';
import type { SimpleGitTestContext } from '../create-test-context';

export async function setUpIgnored({ git, file }: SimpleGitTestContext, paths: string[] = [], filename = '.gitignore') {
await file(filename, paths.join('\n') + '\n');
Expand Down
5 changes: 3 additions & 2 deletions packages/test-utils/src/setup/setup-init.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { SimpleGit } from 'simple-git';
import { SimpleGitTestContext } from '../create-test-context';
import type { SimpleGit } from 'simple-git';

import type { SimpleGitTestContext } from '../create-test-context';

export const GIT_USER_NAME = 'Simple Git Tests';
export const GIT_USER_EMAIL = 'tests@simple-git.dev';
Expand Down
14 changes: 0 additions & 14 deletions simple-git/jest.config.js

This file was deleted.

33 changes: 33 additions & 0 deletions simple-git/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type { Config } from 'jest';

const projectConfig = (type: string): Config => ({
displayName: type,
coverageThreshold: {
global: {
branches: 80,
functions: 80,
lines: 80,
statements: 80,
},
},
coveragePathIgnorePatterns: ['<rootDir>/test/'],
// coverageReporters: ['json', 'lcov', 'text', 'clover'],
roots: ['<rootDir>/src/', '<rootDir>/test/', '<rootDir>/typings/'],
testMatch: [`**/test/${type}/**/*.spec.*`],
});

const config: Config = {
projects: [
{
...projectConfig('unit'),
setupFilesAfterEnv: [
'<rootDir>/test/unit/__fixtures__/debug.ts',
'<rootDir>/test/unit/__fixtures__/file-exists.ts',
'<rootDir>/test/unit/__mocks__/mock-child-process.ts',
],
},
projectConfig('integration'),
],
};

export default config;
29 changes: 0 additions & 29 deletions simple-git/src/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const {
} = require('./lib/tasks/branch');
const { checkIgnoreTask } = require('./lib/tasks/check-ignore');
const { checkIsRepoTask } = require('./lib/tasks/check-is-repo');
const { cloneTask, cloneMirrorTask } = require('./lib/tasks/clone');
const { cleanWithOptionsTask, isCleanOptionsArray } = require('./lib/tasks/clean');
const { diffSummaryTask } = require('./lib/tasks/diff');
const { fetchTask } = require('./lib/tasks/fetch');
Expand Down Expand Up @@ -101,34 +100,6 @@ Git.prototype.stashList = function (options) {
);
};

function createCloneTask(api, task, repoPath, localPath) {
if (typeof repoPath !== 'string') {
return configurationErrorTask(`git.${api}() requires a string 'repoPath'`);
}

return task(repoPath, filterType(localPath, filterString), getTrailingOptions(arguments));
}

/**
* Clone a git repo
*/
Git.prototype.clone = function () {
return this._runTask(
createCloneTask('clone', cloneTask, ...arguments),
trailingFunctionArgument(arguments)
);
};

/**
* Mirror a git repo
*/
Git.prototype.mirror = function () {
return this._runTask(
createCloneTask('mirror', cloneMirrorTask, ...arguments),
trailingFunctionArgument(arguments)
);
};

/**
* Moves one or more files to a new destination.
*
Expand Down
7 changes: 7 additions & 0 deletions simple-git/src/lib/args/pathspec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// biome-ignore lint/complexity/noBannedTypes: Object reference required for WeakMap
const cache = new WeakMap<String, string[]>();

export function pathspec(...paths: string[]) {
Expand All @@ -14,3 +15,9 @@ export function isPathSpec(path: string | unknown): path is string {
export function toPaths(pathSpec: string): string[] {
return cache.get(pathSpec) || [];
}

export function insertBeforePathsIndex(commands: string[]) {
const index = commands.indexOf('--');

return index > -1 ? index : commands.length;
}
2 changes: 1 addition & 1 deletion simple-git/src/lib/errors/git-construct-error.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { SimpleGitOptions } from '../types';
import { GitError } from './git-error';
import { SimpleGitOptions } from '../types';

/**
* The `GitConstructError` is thrown when an error occurs in the constructor
Expand Down
2 changes: 1 addition & 1 deletion simple-git/src/lib/errors/git-plugin-error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SimpleGitOptions, SimpleGitTask } from '../types';
import type { SimpleGitOptions, SimpleGitTask } from '../types';
import { GitError } from './git-error';

export class GitPluginError extends GitError {
Expand Down
7 changes: 3 additions & 4 deletions simple-git/src/lib/git-factory.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { SimpleGitFactory } from '../../typings';

import type { SimpleGitFactory } from '../../typings';
import * as api from './api';
import {
abortPlugin,
Expand All @@ -15,8 +14,8 @@ import {
timeoutPlugin,
} from './plugins';
import { suffixPathsPlugin } from './plugins/suffix-paths.plugin';
import type { SimpleGitOptions } from './types';
import { createInstanceConfig, folderExists } from './utils';
import { SimpleGitOptions } from './types';

const Git = require('../git');

Expand Down Expand Up @@ -59,12 +58,12 @@ export function gitInstanceFactory(
}

plugins.add(blockUnsafeOperationsPlugin(config.unsafe));
plugins.add(suffixPathsPlugin());
plugins.add(completionDetectionPlugin(config.completion));
config.abort && plugins.add(abortPlugin(config.abort));
config.progress && plugins.add(progressMonitorPlugin(config.progress));
config.timeout && plugins.add(timeoutPlugin(config.timeout));
config.spawnOptions && plugins.add(spawnOptionsPlugin(config.spawnOptions));
plugins.add(suffixPathsPlugin());

plugins.add(errorDetectionPlugin(errorDetectionHandler(true)));
config.errors && plugins.add(errorDetectionPlugin(config.errors));
Expand Down
5 changes: 3 additions & 2 deletions simple-git/src/lib/git-logger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import debug, { Debugger } from 'debug';
import debug, { type Debugger } from 'debug';

import type { Maybe } from './types';
import {
append,
filterHasLength,
Expand All @@ -8,7 +10,6 @@ import {
objectToString,
remove,
} from './utils';
import { Maybe } from './types';

debug.formatters.L = (value: any) => String(filterHasLength(value) ? value.length : '-');
debug.formatters.B = (value: Buffer) => {
Expand Down
4 changes: 2 additions & 2 deletions simple-git/src/lib/parsers/parse-branch-delete.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { BranchMultiDeleteResult } from '../../../typings';
import type { BranchMultiDeleteResult } from '../../../typings';
import {
BranchDeletionBatch,
branchDeletionFailure,
branchDeletionSuccess,
} from '../responses/BranchDeleteSummary';
import { TaskParser } from '../types';
import type { TaskParser } from '../types';
import { ExitCodes, LineParser, parseStringResponse } from '../utils';

const deleteSuccessRegex = /(\S+)\s+\(\S+\s([^)]+)\)/;
Expand Down
2 changes: 1 addition & 1 deletion simple-git/src/lib/parsers/parse-commit.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CommitResult } from '../../../typings';
import type { CommitResult } from '../../../typings';
import { LineParser, parseStringResponse } from '../utils';

const parsers: LineParser<CommitResult>[] = [
Expand Down
2 changes: 1 addition & 1 deletion simple-git/src/lib/parsers/parse-diff-summary.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DiffResult } from '../../../typings';
import type { DiffResult } from '../../../typings';
import { LogFormat } from '../args/log-format';
import { DiffSummary } from '../responses/DiffSummary';
import { isDiffNameStatus } from '../tasks/diff-name-status';
Expand Down
2 changes: 1 addition & 1 deletion simple-git/src/lib/parsers/parse-fetch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FetchResult } from '../../../typings';
import type { FetchResult } from '../../../typings';
import { LineParser, parseStringResponse } from '../utils';

const parsers: LineParser<FetchResult>[] = [
Expand Down
Loading