@kaynooo/cli-git 0.16.1 → 0.17.0
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/README.md +1 -1
- package/dist/gm.js +15 -3
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -53,7 +53,7 @@ Prints one line with the branch, its upstream and how far ahead and behind it is
|
|
|
53
53
|
|
|
54
54
|
## gm
|
|
55
55
|
|
|
56
|
-
`gm <branch>` merges the branch into the current one with `git merge --no-edit` and prints what came in: fast-forward or merge commit, the commits and the files changed.
|
|
56
|
+
`gm <branch>` merges the branch into the current one with `git merge --no-edit` and prints what came in: fast-forward or merge commit, the commits and the files changed. Staged changes are refused, and so are unstaged ones in files the merge changes; other unstaged edits stay as they are, through a conflict and gm --abort too.
|
|
57
57
|
|
|
58
58
|
- On a conflict every conflicted file is listed with its conflict regions (the markers and two lines around them, line numbers included) and the exit is 1; `gm --continue` commits once the markers are gone, refusing while one remains, and `gm --abort` gives the merge up.
|
|
59
59
|
- `gm --dry-run <branch>` says whether the merge would conflict, and in which files, with `git merge-tree` and nothing touched.
|
package/dist/gm.js
CHANGED
|
@@ -2724,7 +2724,7 @@ var USAGE = `gm [branch]: merges the branch into the current one with git merge
|
|
|
2724
2724
|
Without a branch, on a terminal, picks one: every branch but the current one with how far it is ahead of and behind it, a preview of what the merge would do (the commits coming in, the files they touch, whether it would conflict and where), enter to merge and ctrl-s to merge with --squash. Without a terminal it lists the branches with that verdict each, clean, conflicts with the files, or merged already. A merge in progress is refused here: gm --continue or gm --abort.
|
|
2725
2725
|
--squash stages the changes of the branch without committing them or recording a merge, to commit with gc; a conflict then leaves the files to resolve and git reset --merge to give up.
|
|
2726
2726
|
|
|
2727
|
-
|
|
2727
|
+
Staged changes are refused, and so are unstaged ones in files the merge changes; other unstaged edits stay as they are, through a conflict and gm --abort too. The output names the outcome (fast-forward, merge commit or already up to date), the commits and the files that came in. On a conflict every conflicted file is listed with its conflict regions (the <<<<<<<, ======= and >>>>>>> lines and two lines around them, line numbers included) and the exit is 1.
|
|
2728
2728
|
gm --dry-run <branch> says whether the merge would conflict and in which files, touching nothing (git merge-tree). gm --continue commits the merge once the markers are gone from the conflicted files, refusing while one remains; gm --abort gives the merge up.`;
|
|
2729
2729
|
var EXITS2 = [[0, "it merged, the branch was already merged, or --dry-run found no conflict"], [1, "a conflict, a dirty tree, an unknown branch, a refused step or git failed"], [2, "outside a git repository or a usage error"]];
|
|
2730
2730
|
var OPTIONS = {
|
|
@@ -2883,6 +2883,19 @@ async function choose2(into) {
|
|
|
2883
2883
|
enter merge, ctrl-s merge --squash`, expect: ["ctrl-s"], searched: 1, preview: async (hidden) => preview2(hidden[0] ?? "") });
|
|
2884
2884
|
return picked === undefined || picked.hidden[0] === undefined ? undefined : { branch: picked.hidden[0], squash: picked.key === "ctrl-s" };
|
|
2885
2885
|
}
|
|
2886
|
+
async function refuseUnsafeChanges(branch) {
|
|
2887
|
+
const paths = async (args) => (await ran([...args, "--name-only", "-z"])).split("\x00").filter((path) => path !== "");
|
|
2888
|
+
const staged = await paths(["diff", "--cached"]);
|
|
2889
|
+
if (staged.length > 0)
|
|
2890
|
+
fail(`staged changes would go into the merge (${staged.join(", ")}): commit them first (gc), or unstage them (gu --staged)`, 1);
|
|
2891
|
+
const dirty = await paths(["diff"]);
|
|
2892
|
+
if (dirty.length === 0)
|
|
2893
|
+
return;
|
|
2894
|
+
const touched = new Set(await paths(["diff", "--no-renames", `HEAD...${branch}`]));
|
|
2895
|
+
const overlap = dirty.filter((path) => touched.has(path));
|
|
2896
|
+
if (overlap.length > 0)
|
|
2897
|
+
fail(`uncommitted changes in files the merge changes (${overlap.join(", ")}): commit them first (gc), or set them aside as a patch (gu)`, 1);
|
|
2898
|
+
}
|
|
2886
2899
|
async function main(argv) {
|
|
2887
2900
|
const { values, positionals } = parse(argv, USAGE, OPTIONS, { positionals: ["[branch]"], exits: EXITS2, replaces: "git merge and then git diff --name-only --diff-filter=U and reading each file for markers", examples: ["gm feature", ["gm --dry-run feature", "whether it would conflict, and where"], ["gm --continue", "commit once the conflicts are resolved"], ["gm --abort", "give the merge up"]] });
|
|
2888
2901
|
const json = values.json === true;
|
|
@@ -2943,8 +2956,7 @@ ${USAGE}`);
|
|
|
2943
2956
|
return dryRun(branch, into, json);
|
|
2944
2957
|
if (await merging())
|
|
2945
2958
|
fail("a merge is already in progress: gm --continue once the conflicts are resolved, or gm --abort", 1);
|
|
2946
|
-
|
|
2947
|
-
fail("the working tree has uncommitted changes, commit or stash them first (gc, git stash)", 1);
|
|
2959
|
+
await refuseUnsafeChanges(branch);
|
|
2948
2960
|
if (await succeeds(["merge-base", "--is-ancestor", branch, "HEAD"])) {
|
|
2949
2961
|
if (json)
|
|
2950
2962
|
printJson({ outcome: "up-to-date", branch, into });
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaynooo/cli-git",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.17.0",
|
|
5
5
|
"description": "gst, gc, gb, gp, gf, gm, gcl, gd and gu: a repository's state in one call, a commit of exactly the paths given, its message checked before anything is staged, a branch picked, nested repositories pushed or fetched, a branch merged with its conflicts listed, a clone into the workspace, the changes per file and an undo that keeps what it takes away.",
|
|
6
6
|
"author": "Kaynooo <contact@kaynooo.fr>",
|
|
7
7
|
"license": "MIT",
|
|
8
|
-
"homepage": "https://
|
|
8
|
+
"homepage": "https://github.com/Kayno0o/cli/tree/main/packages/git#readme",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "git+https://
|
|
11
|
+
"url": "git+https://github.com/Kayno0o/cli.git",
|
|
12
12
|
"directory": "packages/git"
|
|
13
13
|
},
|
|
14
|
-
"bugs": "https://
|
|
14
|
+
"bugs": "https://github.com/Kayno0o/cli/issues",
|
|
15
15
|
"keywords": [
|
|
16
16
|
"claude-code",
|
|
17
17
|
"cli",
|