Skip to content

Commit 9ced5e6

Browse files
authored
Merge pull request #645 from steveukx/fix/ts-api
fix: convert `hashObject` to typescript api
2 parents 9f32df4 + 87bcd6f commit 9ced5e6

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

src/git.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -491,16 +491,6 @@ Git.prototype.getRemotes = function (verbose, then) {
491491
);
492492
};
493493

494-
/**
495-
* Compute object ID from a file
496-
*/
497-
Git.prototype.hashObject = function (path, write) {
498-
return this._runTask(
499-
hashObjectTask(path, write === true),
500-
trailingFunctionArgument(arguments),
501-
);
502-
};
503-
504494
/**
505495
* Call any `git remote` function with arguments passed as an array of strings.
506496
*

src/lib/simple-git-api.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { SimpleGitBase } from '../../typings';
22
import { taskCallback } from './task-callback';
33
import { changeWorkingDirectoryTask } from './tasks/change-working-directory';
4+
import { hashObjectTask } from './tasks/hash-object';
45
import { initTask } from './tasks/init';
56
import { mergeTask } from './tasks/merge';
67
import { pushTask } from './tasks/push';
@@ -11,7 +12,8 @@ import { asArray, filterString, filterType, getTrailingOptions, trailingFunction
1112

1213
export class SimpleGitApi implements SimpleGitBase {
1314

14-
constructor(private _executor: SimpleGitExecutor) {}
15+
constructor(private _executor: SimpleGitExecutor) {
16+
}
1517

1618
private _runTask<T>(task: SimpleGitTask<T>, then?: SimpleGitTaskCallback<T>) {
1719
const chain = this._executor.chain();
@@ -52,7 +54,14 @@ export class SimpleGitApi implements SimpleGitBase {
5254
);
5355
}
5456

55-
init (bare?: boolean | unknown) {
57+
hashObject(path: string, write: boolean | unknown) {
58+
return this._runTask(
59+
hashObjectTask(path, write === true),
60+
trailingFunctionArgument(arguments),
61+
);
62+
}
63+
64+
init(bare?: boolean | unknown) {
5665
return this._runTask(
5766
initTask(bare === true, this._executor.cwd, getTrailingOptions(arguments)),
5867
trailingFunctionArgument(arguments),
@@ -66,7 +75,7 @@ export class SimpleGitApi implements SimpleGitBase {
6675
);
6776
}
6877

69-
mergeFromTo (remote: string, branch: string) {
78+
mergeFromTo(remote: string, branch: string) {
7079
if (!(filterString(remote) && filterString(branch))) {
7180
return this._runTask(configurationErrorTask(
7281
`Git.mergeFromTo requires that the 'remote' and 'branch' arguments are supplied as strings`
@@ -79,7 +88,7 @@ export class SimpleGitApi implements SimpleGitBase {
7988
);
8089
}
8190

82-
outputHandler (handler: outputHandler) {
91+
outputHandler(handler: outputHandler) {
8392
this._executor.outputHandler = handler;
8493
return this;
8594
}
@@ -99,14 +108,14 @@ export class SimpleGitApi implements SimpleGitBase {
99108
);
100109
}
101110

102-
stash () {
111+
stash() {
103112
return this._runTask(
104113
straightThroughStringTask(['stash', ...getTrailingOptions(arguments)]),
105114
trailingFunctionArgument(arguments),
106115
);
107116
}
108117

109-
status () {
118+
status() {
110119
return this._runTask(statusTask(getTrailingOptions(arguments)), trailingFunctionArgument(arguments));
111120
}
112121
}

typings/simple-git.d.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,16 @@ export interface SimpleGitBase {
2222
* Sets the working directory of the subsequent commands.
2323
*/
2424
cwd(directory: { path: string, root?: boolean }, callback?: types.SimpleGitTaskCallback<string>): Response<string>;
25+
2526
cwd<path extends string>(directory: path, callback?: types.SimpleGitTaskCallback<path>): Response<path>;
2627

28+
/**
29+
* Compute object ID from a file
30+
*/
31+
hashObject(path: string, callback?: types.SimpleGitTaskCallback): Response<string>;
32+
33+
hashObject(path: string, write ?: boolean, callback?: types.SimpleGitTaskCallback): Response<string>;
34+
2735
/**
2836
* Initialize a git repo
2937
*/
@@ -368,13 +376,6 @@ export interface SimpleGit extends SimpleGitBase {
368376

369377
getRemotes(verbose: true, callback?: types.SimpleGitTaskCallback<types.RemoteWithRefs[]>): Response<types.RemoteWithRefs[]>;
370378

371-
/**
372-
* Compute object ID from a file
373-
*/
374-
hashObject(path: string, callback?: types.SimpleGitTaskCallback): Response<string>;
375-
376-
hashObject(path: string, write ?: boolean, callback?: types.SimpleGitTaskCallback): Response<string>;
377-
378379
/**
379380
* List remotes by running the `ls-remote` command with any number of arbitrary options
380381
* in either array of object form.

0 commit comments

Comments
 (0)