@forwardimpact/libutil 0.1.91 → 0.1.92
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/git-client.js +25 -6
package/package.json
CHANGED
package/src/git-client.js
CHANGED
|
@@ -56,14 +56,17 @@ export class GitClient {
|
|
|
56
56
|
return this.#runRaw(args, { cwd });
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
/** Return `git status --porcelain` output
|
|
60
|
-
async status({ cwd }) {
|
|
61
|
-
|
|
59
|
+
/** Return `git status --porcelain` output, optionally limited to `paths`. */
|
|
60
|
+
async status({ cwd, paths } = {}) {
|
|
61
|
+
const args = ["status", "--porcelain"];
|
|
62
|
+
if (paths?.length) args.push("--", ...paths);
|
|
63
|
+
return this.#runRaw(args, { cwd });
|
|
62
64
|
}
|
|
63
65
|
|
|
64
66
|
/** Rebase the current branch onto `upstream`, optionally with a merge strategy. */
|
|
65
|
-
async rebase(upstream, { cwd, strategy } = {}) {
|
|
67
|
+
async rebase(upstream, { cwd, strategy, autostash = false } = {}) {
|
|
66
68
|
const args = ["rebase"];
|
|
69
|
+
if (autostash) args.push("--autostash");
|
|
67
70
|
if (strategy) args.push("-X", strategy);
|
|
68
71
|
args.push(upstream);
|
|
69
72
|
return this.#runRaw(args, { cwd, allowFailure: true });
|
|
@@ -75,8 +78,11 @@ export class GitClient {
|
|
|
75
78
|
}
|
|
76
79
|
|
|
77
80
|
/** Merge `ref` into the current branch resolving conflicts with `-X ours`. */
|
|
78
|
-
async mergeOursStrategy({ cwd, ref }) {
|
|
79
|
-
|
|
81
|
+
async mergeOursStrategy({ cwd, ref, autostash = false }) {
|
|
82
|
+
const args = ["merge"];
|
|
83
|
+
if (autostash) args.push("--autostash");
|
|
84
|
+
args.push("-X", "ours", "--no-edit", ref);
|
|
85
|
+
return this.#runRaw(args, { cwd });
|
|
80
86
|
}
|
|
81
87
|
|
|
82
88
|
/** Stage all changes and commit with `message`. */
|
|
@@ -87,6 +93,19 @@ export class GitClient {
|
|
|
87
93
|
return this.#runRaw(args, { cwd });
|
|
88
94
|
}
|
|
89
95
|
|
|
96
|
+
/**
|
|
97
|
+
* Stage and commit only `paths`, leaving the rest of the working tree
|
|
98
|
+
* untouched. The commit carries the same pathspec so content staged by
|
|
99
|
+
* other writers is never swept in.
|
|
100
|
+
*/
|
|
101
|
+
async commitPaths(message, paths, { cwd, author } = {}) {
|
|
102
|
+
await this.#runRaw(["add", "--", ...paths], { cwd });
|
|
103
|
+
const args = ["commit", "-m", message];
|
|
104
|
+
if (author) args.push("--author", author);
|
|
105
|
+
args.push("--", ...paths);
|
|
106
|
+
return this.#runRaw(args, { cwd });
|
|
107
|
+
}
|
|
108
|
+
|
|
90
109
|
/** Push `branch` to `remote`. */
|
|
91
110
|
async push(remote = "origin", branch, { cwd, force = false } = {}) {
|
|
92
111
|
const args = ["push", remote];
|