git-chopstick-core 0.1.1 → 0.1.2
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 +324 -32
- package/dist/git/add.d.ts +9 -0
- package/dist/git/add.js +11 -0
- package/dist/git/add.js.map +1 -0
- package/dist/git/apply.d.ts +33 -0
- package/dist/git/apply.js +103 -0
- package/dist/git/apply.js.map +1 -0
- package/dist/git/authentication.d.ts +5 -0
- package/dist/git/authentication.js +19 -0
- package/dist/git/authentication.js.map +1 -0
- package/dist/git/branch.d.ts +43 -0
- package/dist/git/branch.js +150 -0
- package/dist/git/branch.js.map +1 -0
- package/dist/git/checkout-index.d.ts +19 -0
- package/dist/git/checkout-index.js +29 -0
- package/dist/git/checkout-index.js.map +1 -0
- package/dist/git/checkout.d.ts +46 -0
- package/dist/git/checkout.js +126 -0
- package/dist/git/checkout.js.map +1 -0
- package/dist/git/cherry-pick.d.ts +82 -0
- package/dist/git/cherry-pick.js +371 -0
- package/dist/git/cherry-pick.js.map +1 -0
- package/dist/git/clean.d.ts +5 -0
- package/dist/git/clean.js +8 -0
- package/dist/git/clean.js.map +1 -0
- package/dist/git/clone.d.ts +22 -0
- package/dist/git/clone.js +58 -0
- package/dist/git/clone.js.map +1 -0
- package/dist/git/coerce-to-buffer.d.ts +1 -0
- package/dist/git/coerce-to-buffer.js +2 -0
- package/dist/git/coerce-to-buffer.js.map +1 -0
- package/dist/git/coerce-to-string.d.ts +1 -0
- package/dist/git/coerce-to-string.js +2 -0
- package/dist/git/coerce-to-string.js.map +1 -0
- package/dist/git/commit.d.ts +25 -0
- package/dist/git/commit.js +99 -0
- package/dist/git/commit.js.map +1 -0
- package/dist/git/config.d.ts +98 -0
- package/dist/git/config.js +249 -0
- package/dist/git/config.js.map +1 -0
- package/dist/git/core.d.ts +167 -0
- package/dist/git/core.js +368 -0
- package/dist/git/core.js.map +1 -0
- package/dist/git/create-tail-stream.d.ts +4 -0
- package/dist/git/create-tail-stream.js +30 -0
- package/dist/git/create-tail-stream.js.map +1 -0
- package/dist/git/credential.d.ts +5 -0
- package/dist/git/credential.js +64 -0
- package/dist/git/credential.js.map +1 -0
- package/dist/git/description.d.ts +5 -0
- package/dist/git/description.js +24 -0
- package/dist/git/description.js.map +1 -0
- package/dist/git/diff-check.d.ts +7 -0
- package/dist/git/diff-check.js +17 -0
- package/dist/git/diff-check.js.map +1 -0
- package/dist/git/diff-index.d.ts +31 -0
- package/dist/git/diff-index.js +76 -0
- package/dist/git/diff-index.js.map +1 -0
- package/dist/git/diff.d.ts +81 -0
- package/dist/git/diff.js +611 -0
- package/dist/git/diff.js.map +1 -0
- package/dist/git/environment.d.ts +51 -0
- package/dist/git/environment.js +97 -0
- package/dist/git/environment.js.map +1 -0
- package/dist/git/exec.d.ts +109 -0
- package/dist/git/exec.js +224 -0
- package/dist/git/exec.js.map +1 -0
- package/dist/git/fetch.d.ts +25 -0
- package/dist/git/fetch.js +100 -0
- package/dist/git/fetch.js.map +1 -0
- package/dist/git/for-each-ref.d.ts +13 -0
- package/dist/git/for-each-ref.js +114 -0
- package/dist/git/for-each-ref.js.map +1 -0
- package/dist/git/format-patch.d.ts +10 -0
- package/dist/git/format-patch.js +16 -0
- package/dist/git/format-patch.js.map +1 -0
- package/dist/git/git-delimiter-parser.d.ts +38 -0
- package/dist/git/git-delimiter-parser.js +79 -0
- package/dist/git/git-delimiter-parser.js.map +1 -0
- package/dist/git/gitignore.d.ts +26 -0
- package/dist/git/gitignore.js +124 -0
- package/dist/git/gitignore.js.map +1 -0
- package/dist/git/index.d.ts +46 -0
- package/dist/git/index.js +47 -0
- package/dist/git/index.js.map +1 -0
- package/dist/git/init.d.ts +2 -0
- package/dist/git/init.js +7 -0
- package/dist/git/init.js.map +1 -0
- package/dist/git/interpret-trailers.d.ts +88 -0
- package/dist/git/interpret-trailers.js +130 -0
- package/dist/git/interpret-trailers.js.map +1 -0
- package/dist/git/lfs.d.ts +25 -0
- package/dist/git/lfs.js +73 -0
- package/dist/git/lfs.js.map +1 -0
- package/dist/git/log.d.ts +56 -0
- package/dist/git/log.js +258 -0
- package/dist/git/log.js.map +1 -0
- package/dist/git/merge-tree.d.ts +13 -0
- package/dist/git/merge-tree.js +24 -0
- package/dist/git/merge-tree.js.map +1 -0
- package/dist/git/merge.d.ts +50 -0
- package/dist/git/merge.js +111 -0
- package/dist/git/merge.js.map +1 -0
- package/dist/git/multi-operation-terminal-output.d.ts +20 -0
- package/dist/git/multi-operation-terminal-output.js +56 -0
- package/dist/git/multi-operation-terminal-output.js.map +1 -0
- package/dist/git/pull.d.ts +24 -0
- package/dist/git/pull.js +91 -0
- package/dist/git/pull.js.map +1 -0
- package/dist/git/push-terminal-chunk.d.ts +19 -0
- package/dist/git/push-terminal-chunk.js +36 -0
- package/dist/git/push-terminal-chunk.js.map +1 -0
- package/dist/git/push.d.ts +42 -0
- package/dist/git/push.js +80 -0
- package/dist/git/push.js.map +1 -0
- package/dist/git/rebase.d.ts +119 -0
- package/dist/git/rebase.js +415 -0
- package/dist/git/rebase.js.map +1 -0
- package/dist/git/reflog.d.ts +14 -0
- package/dist/git/reflog.js +88 -0
- package/dist/git/reflog.js.map +1 -0
- package/dist/git/refs.d.ts +26 -0
- package/dist/git/refs.js +53 -0
- package/dist/git/refs.js.map +1 -0
- package/dist/git/remote.d.ts +31 -0
- package/dist/git/remote.js +81 -0
- package/dist/git/remote.js.map +1 -0
- package/dist/git/reorder.d.ts +23 -0
- package/dist/git/reorder.js +111 -0
- package/dist/git/reorder.js.map +1 -0
- package/dist/git/reset.d.ts +41 -0
- package/dist/git/reset.js +86 -0
- package/dist/git/reset.js.map +1 -0
- package/dist/git/rev-list.d.ts +67 -0
- package/dist/git/rev-list.js +157 -0
- package/dist/git/rev-list.js.map +1 -0
- package/dist/git/rev-parse.d.ts +24 -0
- package/dist/git/rev-parse.js +65 -0
- package/dist/git/rev-parse.js.map +1 -0
- package/dist/git/revert.d.ts +12 -0
- package/dist/git/revert.js +30 -0
- package/dist/git/revert.js.map +1 -0
- package/dist/git/rm.d.ts +12 -0
- package/dist/git/rm.js +22 -0
- package/dist/git/rm.js.map +1 -0
- package/dist/git/show.d.ts +42 -0
- package/dist/git/show.js +59 -0
- package/dist/git/show.js.map +1 -0
- package/dist/git/spawn.d.ts +18 -0
- package/dist/git/spawn.js +16 -0
- package/dist/git/spawn.js.map +1 -0
- package/dist/git/squash.d.ts +28 -0
- package/dist/git/squash.js +127 -0
- package/dist/git/squash.js.map +1 -0
- package/dist/git/stage.d.ts +21 -0
- package/dist/git/stage.js +72 -0
- package/dist/git/stage.js.map +1 -0
- package/dist/git/stash.d.ts +53 -0
- package/dist/git/stash.js +204 -0
- package/dist/git/stash.js.map +1 -0
- package/dist/git/status.d.ts +39 -0
- package/dist/git/status.js +293 -0
- package/dist/git/status.js.map +1 -0
- package/dist/git/submodule.d.ts +20 -0
- package/dist/git/submodule.js +153 -0
- package/dist/git/submodule.js.map +1 -0
- package/dist/git/tag.d.ts +32 -0
- package/dist/git/tag.js +101 -0
- package/dist/git/tag.js.map +1 -0
- package/dist/git/update-index.d.ts +11 -0
- package/dist/git/update-index.js +99 -0
- package/dist/git/update-index.js.map +1 -0
- package/dist/git/update-ref.d.ts +23 -0
- package/dist/git/update-ref.js +32 -0
- package/dist/git/update-ref.js.map +1 -0
- package/dist/git/var.d.ts +18 -0
- package/dist/git/var.js +33 -0
- package/dist/git/var.js.map +1 -0
- package/dist/git/worktree-include.d.ts +42 -0
- package/dist/git/worktree-include.js +109 -0
- package/dist/git/worktree-include.js.map +1 -0
- package/dist/git/worktree.d.ts +25 -0
- package/dist/git/worktree.js +139 -0
- package/dist/git/worktree.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/api.d.ts +2 -0
- package/dist/lib/api.js +7 -0
- package/dist/lib/api.js.map +1 -0
- package/dist/lib/diff-parser.d.ts +20 -0
- package/dist/lib/diff-parser.js +184 -0
- package/dist/lib/diff-parser.js.map +1 -0
- package/dist/lib/directory-exists.d.ts +1 -0
- package/dist/lib/directory-exists.js +11 -0
- package/dist/lib/directory-exists.js.map +1 -0
- package/dist/lib/errno-exception.d.ts +6 -0
- package/dist/lib/errno-exception.js +6 -0
- package/dist/lib/errno-exception.js.map +1 -0
- package/dist/lib/fatal-error.d.ts +4 -0
- package/dist/lib/fatal-error.js +18 -0
- package/dist/lib/fatal-error.js.map +1 -0
- package/dist/lib/feature-flag.d.ts +14 -0
- package/dist/lib/feature-flag.js +25 -0
- package/dist/lib/feature-flag.js.map +1 -0
- package/dist/lib/file-system.d.ts +1 -0
- package/dist/lib/file-system.js +7 -0
- package/dist/lib/file-system.js.map +1 -0
- package/dist/lib/get-old-path.d.ts +2 -0
- package/dist/lib/get-old-path.js +9 -0
- package/dist/lib/get-old-path.js.map +1 -0
- package/dist/lib/git/environment.d.ts +3 -0
- package/dist/lib/git/environment.js +7 -0
- package/dist/lib/git/environment.js.map +1 -0
- package/dist/lib/git-perf.d.ts +1 -0
- package/dist/lib/git-perf.js +4 -0
- package/dist/lib/git-perf.js.map +1 -0
- package/dist/lib/helpers/default-branch.d.ts +1 -0
- package/dist/lib/helpers/default-branch.js +4 -0
- package/dist/lib/helpers/default-branch.js.map +1 -0
- package/dist/lib/helpers/path.d.ts +1 -0
- package/dist/lib/helpers/path.js +5 -0
- package/dist/lib/helpers/path.js.map +1 -0
- package/dist/lib/hooks/with-hooks-env.d.ts +3 -0
- package/dist/lib/hooks/with-hooks-env.js +4 -0
- package/dist/lib/hooks/with-hooks-env.js.map +1 -0
- package/dist/lib/merge.d.ts +1 -0
- package/dist/lib/merge.js +4 -0
- package/dist/lib/merge.js.map +1 -0
- package/dist/lib/noop.d.ts +1 -0
- package/dist/lib/noop.js +2 -0
- package/dist/lib/noop.js.map +1 -0
- package/dist/lib/patch-formatter.d.ts +5 -0
- package/dist/lib/patch-formatter.js +7 -0
- package/dist/lib/patch-formatter.js.map +1 -0
- package/dist/lib/path-exists.d.ts +1 -0
- package/dist/lib/path-exists.js +3 -0
- package/dist/lib/path-exists.js.map +1 -0
- package/dist/lib/progress/from-process.d.ts +2 -0
- package/dist/lib/progress/from-process.js +4 -0
- package/dist/lib/progress/from-process.js.map +1 -0
- package/dist/lib/progress/index.d.ts +49 -0
- package/dist/lib/progress/index.js +32 -0
- package/dist/lib/progress/index.js.map +1 -0
- package/dist/lib/progress/revert.d.ts +8 -0
- package/dist/lib/progress/revert.js +15 -0
- package/dist/lib/progress/revert.js.map +1 -0
- package/dist/lib/rebase.d.ts +1 -0
- package/dist/lib/rebase.js +4 -0
- package/dist/lib/rebase.js.map +1 -0
- package/dist/lib/remove-remote-prefix.d.ts +1 -0
- package/dist/lib/remove-remote-prefix.js +5 -0
- package/dist/lib/remove-remote-prefix.js.map +1 -0
- package/dist/lib/resolve-git-proxy.d.ts +1 -0
- package/dist/lib/resolve-git-proxy.js +4 -0
- package/dist/lib/resolve-git-proxy.js.map +1 -0
- package/dist/lib/round.d.ts +1 -0
- package/dist/lib/round.js +5 -0
- package/dist/lib/round.js.map +1 -0
- package/dist/lib/split-buffer.d.ts +1 -0
- package/dist/lib/split-buffer.js +15 -0
- package/dist/lib/split-buffer.js.map +1 -0
- package/dist/lib/status-parser.d.ts +19 -0
- package/dist/lib/status-parser.js +137 -0
- package/dist/lib/status-parser.js.map +1 -0
- package/dist/lib/stores/helpers/find-default-remote.d.ts +1 -0
- package/dist/lib/stores/helpers/find-default-remote.js +4 -0
- package/dist/lib/stores/helpers/find-default-remote.js.map +1 -0
- package/dist/lib/trampoline/trampoline-environment.d.ts +1 -0
- package/dist/lib/trampoline/trampoline-environment.js +4 -0
- package/dist/lib/trampoline/trampoline-environment.js.map +1 -0
- package/dist/models/branch.d.ts +44 -0
- package/dist/models/branch.js +59 -0
- package/dist/models/branch.js.map +1 -0
- package/dist/models/cherry-pick.d.ts +11 -0
- package/dist/models/cherry-pick.js +2 -0
- package/dist/models/cherry-pick.js.map +1 -0
- package/dist/models/clone-options.d.ts +6 -0
- package/dist/models/clone-options.js +2 -0
- package/dist/models/clone-options.js.map +1 -0
- package/dist/models/commit-identity.d.ts +9 -0
- package/dist/models/commit-identity.js +34 -0
- package/dist/models/commit-identity.js.map +1 -0
- package/dist/models/commit.d.ts +30 -0
- package/dist/models/commit.js +32 -0
- package/dist/models/commit.js.map +1 -0
- package/dist/models/computed-action.d.ts +6 -0
- package/dist/models/computed-action.js +8 -0
- package/dist/models/computed-action.js.map +1 -0
- package/dist/models/diff/diff-data.d.ts +53 -0
- package/dist/models/diff/diff-data.js +19 -0
- package/dist/models/diff/diff-data.js.map +1 -0
- package/dist/models/diff/diff-line.d.ts +18 -0
- package/dist/models/diff/diff-line.js +33 -0
- package/dist/models/diff/diff-line.js.map +1 -0
- package/dist/models/diff/diff-selection.d.ts +22 -0
- package/dist/models/diff/diff-selection.js +127 -0
- package/dist/models/diff/diff-selection.js.map +1 -0
- package/dist/models/diff/image-diff.d.ts +6 -0
- package/dist/models/diff/image-diff.js +8 -0
- package/dist/models/diff/image-diff.js.map +1 -0
- package/dist/models/diff/image.d.ts +7 -0
- package/dist/models/diff/image.js +13 -0
- package/dist/models/diff/image.js.map +1 -0
- package/dist/models/diff/index.d.ts +6 -0
- package/dist/models/diff/index.js +7 -0
- package/dist/models/diff/index.js.map +1 -0
- package/dist/models/diff/raw-diff.d.ts +32 -0
- package/dist/models/diff/raw-diff.js +38 -0
- package/dist/models/diff/raw-diff.js.map +1 -0
- package/dist/models/git-author.d.ts +7 -0
- package/dist/models/git-author.js +18 -0
- package/dist/models/git-author.js.map +1 -0
- package/dist/models/index.d.ts +21 -0
- package/dist/models/index.js +20 -0
- package/dist/models/index.js.map +1 -0
- package/dist/models/manual-conflict-resolution.d.ts +4 -0
- package/dist/models/manual-conflict-resolution.js +6 -0
- package/dist/models/manual-conflict-resolution.js.map +1 -0
- package/dist/models/merge.d.ts +6 -0
- package/dist/models/merge.js +2 -0
- package/dist/models/merge.js.map +1 -0
- package/dist/models/multi-commit-operation.d.ts +6 -0
- package/dist/models/multi-commit-operation.js +8 -0
- package/dist/models/multi-commit-operation.js.map +1 -0
- package/dist/models/progress.d.ts +41 -0
- package/dist/models/progress.js +7 -0
- package/dist/models/progress.js.map +1 -0
- package/dist/models/rebase.d.ts +17 -0
- package/dist/models/rebase.js +8 -0
- package/dist/models/rebase.js.map +1 -0
- package/dist/models/remote.d.ts +5 -0
- package/dist/models/remote.js +8 -0
- package/dist/models/remote.js.map +1 -0
- package/dist/models/repository.d.ts +7 -0
- package/dist/models/repository.js +15 -0
- package/dist/models/repository.js.map +1 -0
- package/dist/models/stash-entry.d.ts +20 -0
- package/dist/models/stash-entry.js +7 -0
- package/dist/models/stash-entry.js.map +1 -0
- package/dist/models/status.d.ts +166 -0
- package/dist/models/status.js +135 -0
- package/dist/models/status.js.map +1 -0
- package/dist/models/submodule.d.ts +12 -0
- package/dist/models/submodule.js +2 -0
- package/dist/models/submodule.js.map +1 -0
- package/dist/models/worktree.d.ts +10 -0
- package/dist/models/worktree.js +2 -0
- package/dist/models/worktree.js.map +1 -0
- package/package.json +13 -4
- package/src/git/add.ts +3 -3
- package/src/git/apply.ts +8 -8
- package/src/git/authentication.ts +3 -2
- package/src/git/branch.ts +10 -10
- package/src/git/checkout-index.ts +2 -2
- package/src/git/checkout.ts +12 -12
- package/src/git/cherry-pick.ts +16 -16
- package/src/git/clean.ts +2 -2
- package/src/git/clone.ts +6 -6
- package/src/git/commit.ts +7 -7
- package/src/git/config.ts +2 -2
- package/src/git/core.ts +8 -8
- package/src/git/credential.ts +1 -1
- package/src/git/diff-check.ts +1 -1
- package/src/git/diff-index.ts +2 -2
- package/src/git/diff.ts +18 -18
- package/src/git/environment.ts +5 -5
- package/src/git/fetch.ts +7 -7
- package/src/git/for-each-ref.ts +5 -5
- package/src/git/format-patch.ts +3 -3
- package/src/git/git-delimiter-parser.ts +1 -1
- package/src/git/gitignore.ts +2 -2
- package/src/git/index.ts +46 -36
- package/src/git/init.ts +2 -2
- package/src/git/interpret-trailers.ts +3 -3
- package/src/git/lfs.ts +2 -2
- package/src/git/log.ts +8 -8
- package/src/git/merge-tree.ts +5 -5
- package/src/git/merge.ts +5 -5
- package/src/git/multi-operation-terminal-output.ts +3 -3
- package/src/git/pull.ts +7 -7
- package/src/git/push-terminal-chunk.ts +1 -1
- package/src/git/push.ts +7 -7
- package/src/git/rebase.ts +16 -16
- package/src/git/reflog.ts +2 -2
- package/src/git/refs.ts +2 -2
- package/src/git/remote.ts +6 -6
- package/src/git/reorder.ts +7 -7
- package/src/git/reset.ts +3 -3
- package/src/git/rev-list.ts +5 -5
- package/src/git/rev-parse.ts +2 -2
- package/src/git/revert.ts +8 -8
- package/src/git/rm.ts +3 -3
- package/src/git/show.ts +4 -4
- package/src/git/spawn.ts +3 -3
- package/src/git/squash.ts +7 -7
- package/src/git/stage.ts +7 -7
- package/src/git/stash.ts +10 -10
- package/src/git/status.ts +13 -13
- package/src/git/submodule.ts +9 -9
- package/src/git/tag.ts +4 -4
- package/src/git/update-index.ts +5 -5
- package/src/git/update-ref.ts +2 -2
- package/src/git/var.ts +3 -3
- package/src/git/worktree-include.ts +3 -3
- package/src/git/worktree.ts +4 -4
- package/src/index.ts +9 -21
- package/src/lib/diff-parser.ts +2 -2
- package/src/lib/get-old-path.ts +1 -1
- package/src/lib/git/environment.ts +1 -1
- package/src/lib/patch-formatter.ts +3 -3
- package/src/lib/progress/from-process.ts +1 -1
- package/src/lib/progress/index.ts +1 -1
- package/src/lib/status-parser.ts +2 -2
- package/src/models/branch.ts +1 -1
- package/src/models/cherry-pick.ts +2 -2
- package/src/models/commit.ts +1 -1
- package/src/models/diff/diff-data.ts +3 -3
- package/src/models/diff/index.ts +6 -6
- package/src/models/diff/raw-diff.ts +1 -1
- package/src/models/index.ts +36 -0
- package/src/models/rebase.ts +2 -2
- package/src/models/stash-entry.ts +1 -1
- package/src/models/status.ts +1 -1
- package/examples/get-status.ts +0 -84
- package/tsconfig.json +0 -17
package/README.md
CHANGED
|
@@ -1,62 +1,354 @@
|
|
|
1
1
|
# git-chopstick-core
|
|
2
2
|
|
|
3
|
-
A standalone Git backend library extracted from [GitHub Desktop](https://github.com/desktop/desktop). Provides TypeScript-first wrappers around the Git CLI for repository operations.
|
|
3
|
+
A standalone Git backend library extracted from [GitHub Desktop](https://github.com/desktop/desktop). Provides TypeScript-first wrappers around the Git CLI for repository operations — no native bindings, no Electron dependencies, just `child_process.spawn('git', ...)`.
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
- **
|
|
8
|
-
- **Full dugite replacement** —
|
|
7
|
+
- **45+ Git command wrappers** — every major operation: status, diff, log, branch (CRUD), commit, merge, rebase, stash, worktree, fetch, push, pull, cherry-pick, revert, tag, clone, init, clean, config, submodule, LFS, and more
|
|
8
|
+
- **Full dugite replacement** — direct `child_process.spawn('git', ...)` with 50+ typed error codes
|
|
9
9
|
- **Pure CLI-based** — works with the user's installed Git, no native bindings
|
|
10
|
-
- **TypeScript-first** — complete type definitions for all
|
|
11
|
-
- **Zero Electron dependencies** —
|
|
10
|
+
- **TypeScript-first** — complete type definitions for all models and operations (`strict: true`)
|
|
11
|
+
- **Zero Electron dependencies** — works in Node.js ≥18 or Bun
|
|
12
|
+
- **Barrel exports** — import everything from a single entry point
|
|
12
13
|
|
|
13
|
-
##
|
|
14
|
+
## Installation
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
```bash
|
|
17
|
+
npm install git-chopstick-core
|
|
18
|
+
# or via file path for local development:
|
|
19
|
+
npm install file:../path/to/git-chopstick-core
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
> **Note:** Not yet published on npm. Use a `file:` dependency or git URL.
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import { Repository, getStatus, GitError } from 'git-chopstick-core'
|
|
28
|
+
|
|
29
|
+
const repo = new Repository('/path/to/repo', 1)
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
const status = await getStatus(repo)
|
|
33
|
+
console.log(`🌿 ${status.currentBranch}`)
|
|
34
|
+
console.log(`📝 ${status.workingDirectory.files.length} changed files`)
|
|
35
|
+
} catch (e) {
|
|
36
|
+
if (e instanceof GitError) {
|
|
37
|
+
console.error(`Git error: ${e.message}`)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Usage Examples
|
|
43
|
+
|
|
44
|
+
### Repository Status
|
|
16
45
|
|
|
17
46
|
```typescript
|
|
18
|
-
import { Repository } from 'git-chopstick-core
|
|
19
|
-
import { getStatus } from 'git-chopstick-core/src/git/status.js'
|
|
47
|
+
import { Repository, getStatus } from 'git-chopstick-core'
|
|
20
48
|
|
|
21
49
|
const repo = new Repository('/path/to/repo', 1)
|
|
22
50
|
const status = await getStatus(repo)
|
|
23
51
|
|
|
24
|
-
|
|
25
|
-
console.log(
|
|
52
|
+
if (!status) {
|
|
53
|
+
console.log('Not a git repository')
|
|
54
|
+
process.exit(1)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
console.log(`Branch: ${status.currentBranch ?? '(detached)'}`)
|
|
58
|
+
console.log(`Upstream: ${status.currentUpstreamBranch ?? 'none'}`)
|
|
59
|
+
|
|
60
|
+
if (status.branchAheadBehind) {
|
|
61
|
+
console.log(`Ahead: ${status.branchAheadBehind.ahead}`)
|
|
62
|
+
console.log(`Behind: ${status.branchAheadBehind.behind}`)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Working directory changes
|
|
66
|
+
for (const file of status.workingDirectory.files) {
|
|
67
|
+
console.log(`${file.status.kind}: ${file.path}`)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Conflict detection
|
|
71
|
+
if (status.doConflictedFilesExist) {
|
|
72
|
+
console.log('⚠️ Merge conflicts detected')
|
|
73
|
+
}
|
|
74
|
+
if (status.rebaseInternalState) {
|
|
75
|
+
console.log(`🔄 Rebase onto ${status.rebaseInternalState.targetBranch}`)
|
|
76
|
+
}
|
|
26
77
|
```
|
|
27
78
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
79
|
+
### Create a Commit
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
import { Repository, getStatus, createCommit } from 'git-chopstick-core'
|
|
83
|
+
|
|
84
|
+
const repo = new Repository('/path/to/repo', 1)
|
|
85
|
+
const status = await getStatus(repo)
|
|
86
|
+
|
|
87
|
+
// Stage and commit all tracked files
|
|
88
|
+
const files = status!.workingDirectory.files
|
|
89
|
+
const sha = await createCommit(repo, 'feat: add new feature', files)
|
|
90
|
+
console.log(`Committed: ${sha}`)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Branch Operations
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
import {
|
|
97
|
+
Repository, Branch, BranchType, createBranch,
|
|
98
|
+
deleteLocalBranch, renameBranch, getBranches
|
|
99
|
+
} from 'git-chopstick-core'
|
|
100
|
+
|
|
101
|
+
const repo = new Repository('/path/to/repo', 1)
|
|
102
|
+
|
|
103
|
+
// Create a branch
|
|
104
|
+
await createBranch(repo, 'feature/new-feature', 'main')
|
|
105
|
+
|
|
106
|
+
// List all branches
|
|
107
|
+
const branches = await getBranches(repo)
|
|
108
|
+
for (const branch of branches) {
|
|
109
|
+
const icon = branch.type === BranchType.Local ? '🌿' : '🌐'
|
|
110
|
+
console.log(`${icon} ${branch.name}`)
|
|
34
111
|
}
|
|
112
|
+
|
|
113
|
+
// Rename
|
|
114
|
+
await renameBranch(repo, branches[0], 'feature/renamed')
|
|
115
|
+
|
|
116
|
+
// Delete
|
|
117
|
+
await deleteLocalBranch(repo, 'feature/old-branch')
|
|
35
118
|
```
|
|
36
119
|
|
|
37
|
-
###
|
|
120
|
+
### Merge
|
|
38
121
|
|
|
39
|
-
```
|
|
40
|
-
|
|
122
|
+
```typescript
|
|
123
|
+
import {
|
|
124
|
+
Repository, merge, MergeResult,
|
|
125
|
+
abortMerge, getMergeBase, isMergeHeadSet
|
|
126
|
+
} from 'git-chopstick-core'
|
|
127
|
+
|
|
128
|
+
const repo = new Repository('/path/to/repo', 1)
|
|
129
|
+
|
|
130
|
+
const result = await merge(repo, 'feature/new-feature')
|
|
131
|
+
|
|
132
|
+
switch (result) {
|
|
133
|
+
case MergeResult.Success:
|
|
134
|
+
console.log('✓ Merge successful')
|
|
135
|
+
break
|
|
136
|
+
case MergeResult.AlreadyUpToDate:
|
|
137
|
+
console.log('✓ Already up to date')
|
|
138
|
+
break
|
|
139
|
+
case MergeResult.Failed:
|
|
140
|
+
console.log('✗ Merge failed — resolve conflicts')
|
|
141
|
+
break
|
|
142
|
+
}
|
|
41
143
|
```
|
|
42
144
|
|
|
145
|
+
### Push & Pull
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
import {
|
|
149
|
+
Repository, push, pull, getRemotes, getStatus
|
|
150
|
+
} from 'git-chopstick-core'
|
|
151
|
+
|
|
152
|
+
const repo = new Repository('/path/to/repo', 1)
|
|
153
|
+
const [remote] = await getRemotes(repo)
|
|
154
|
+
const status = await getStatus(repo)
|
|
155
|
+
|
|
156
|
+
// Push current branch
|
|
157
|
+
await push(repo, remote, status!.currentBranch!, null, null)
|
|
158
|
+
|
|
159
|
+
// Pull from remote
|
|
160
|
+
await pull(repo, remote)
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Error Handling
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
import {
|
|
167
|
+
Repository, merge, GitError, GitErrorCodes
|
|
168
|
+
} from 'git-chopstick-core'
|
|
169
|
+
|
|
170
|
+
const repo = new Repository('/path/to/repo', 1)
|
|
171
|
+
|
|
172
|
+
try {
|
|
173
|
+
await merge(repo, 'other-branch')
|
|
174
|
+
} catch (e) {
|
|
175
|
+
if (e instanceof GitError) {
|
|
176
|
+
// e.result.gitError is the error code enum
|
|
177
|
+
switch (e.result.gitError) {
|
|
178
|
+
case GitErrorCodes.MergeConflicts:
|
|
179
|
+
console.error('Conflicts need resolution')
|
|
180
|
+
break
|
|
181
|
+
case GitErrorCodes.RebaseConflicts:
|
|
182
|
+
console.error('Rebase conflicts')
|
|
183
|
+
break
|
|
184
|
+
case GitErrorCodes.PushNotFastForward:
|
|
185
|
+
console.error('Push rejected — pull first')
|
|
186
|
+
break
|
|
187
|
+
case GitErrorCodes.HTTPSAuthenticationFailed:
|
|
188
|
+
case GitErrorCodes.SSHAuthenticationFailed:
|
|
189
|
+
console.error('Authentication failed')
|
|
190
|
+
break
|
|
191
|
+
default:
|
|
192
|
+
console.error(`Git error: ${e.result.gitErrorDescription}`)
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
## API Reference
|
|
199
|
+
|
|
200
|
+
### Git Operations (`src/git/`)
|
|
201
|
+
|
|
202
|
+
| Module | Key Exports | Description |
|
|
203
|
+
|--------|-------------|-------------|
|
|
204
|
+
| `add` | `addConflictedFile` | Stage a resolved conflicted file |
|
|
205
|
+
| `apply` | `applyPatchToIndex`, `checkPatch`, `discardChangesFromSelection` | Apply patches to the index |
|
|
206
|
+
| `branch` | `createBranch`, `renameBranch`, `deleteLocalBranch`, `deleteRemoteBranch`, `getBranchNames`, `getBranchesPointedAt`, `getMergedBranches` | Branch CRUD |
|
|
207
|
+
| `checkout` | `checkoutBranch`, `checkoutCommit`, `checkoutPaths`, `checkoutConflictedFile` | Checkout branches/commits/files |
|
|
208
|
+
| `checkout-index` | `checkoutIndex` | Checkout files from the index |
|
|
209
|
+
| `cherry-pick` | `cherryPick`, `continueCherryPick`, `abortCherryPick`, `getCherryPickSnapshot` | Cherry-pick commits |
|
|
210
|
+
| `clean` | `cleanUntrackedFiles` | Remove untracked files |
|
|
211
|
+
| `clone` | `clone` | Clone a repository |
|
|
212
|
+
| `commit` | `createCommit`, `createMergeCommit` | Create commits |
|
|
213
|
+
| `config` | `getConfigValue`, `getGlobalConfigValue`, `getBooleanConfigValue` | Read git config |
|
|
214
|
+
| `diff` | `getWorkingDirectoryDiff`, `getCommitDiff`, `getBranchMergeBaseDiff`, `getCommitRangeDiff`, `getBinaryPaths` | Diff rendering |
|
|
215
|
+
| `diff-index` | `getIndexChanges` | Compare index with tree |
|
|
216
|
+
| `fetch` | `fetch`, `fetchRefspec`, `fastForwardBranches` | Fetch from remotes |
|
|
217
|
+
| `for-each-ref` | `getBranches`, `getBranchesDifferingFromUpstream` | List refs |
|
|
218
|
+
| `format-patch` | `formatPatch` | Generate patch files |
|
|
219
|
+
| `gitignore` | `readGitIgnoreAtRoot`, `saveGitIgnore`, `appendIgnoreRule`, `escapeGitSpecialCharacters` | Manage .gitignore |
|
|
220
|
+
| `init` | `initGitRepository` | Initialize a repo |
|
|
221
|
+
| `interpret-trailers` | `parseRawUnfoldedTrailers`, `isCoAuthoredByTrailer`, `getTrailerSeparatorCharacters` | Git trailer parsing |
|
|
222
|
+
| `lfs` | `installGlobalLFSFilters`, `isUsingLFS`, `isTrackedByLFS`, `filesNotTrackedByLFS` | Git LFS support |
|
|
223
|
+
| `log` | `getCommits`, `getCommit`, `getChangedFiles`, `getAuthors` | Commit history |
|
|
224
|
+
| `merge` | `merge`, `getMergeBase`, `abortMerge` | Merge branches |
|
|
225
|
+
| `merge-tree` | `determineMergeability` | Test mergeability without merging |
|
|
226
|
+
| `pull` | `pull` | Pull from remote |
|
|
227
|
+
| `push` | `push` | Push to remote |
|
|
228
|
+
| `rebase` | `rebase`, `continueRebase`, `abortRebase`, `rebaseInteractive`, `getRebaseInternalState`, `getRebaseSnapshot` | Rebase operations |
|
|
229
|
+
| `reflog` | `getRecentBranches`, `getBranchCheckouts` | Reflog inspection |
|
|
230
|
+
| `refs` | `formatAsLocalRef`, `getSymbolicRef` | Ref manipulation |
|
|
231
|
+
| `remote` | `getRemotes`, `addRemote`, `removeRemote` | Remote management |
|
|
232
|
+
| `reorder` | `reorder` | Interactive rebase reordering |
|
|
233
|
+
| `reset` | `reset`, `resetPaths`, `unstageAll` | Reset operations |
|
|
234
|
+
| `revert` | `revertCommit` | Revert a commit |
|
|
235
|
+
| `rev-list` | `getAheadBehind`, `getBranchAheadBehind`, `revRange`, `revSymmetricDifference` | Commit range queries |
|
|
236
|
+
| `rev-parse` | `getRepositoryType`, `getUpstreamRefForRef`, `getCurrentUpstreamRef` | Rev parsing |
|
|
237
|
+
| `rm` | `removeConflictedFile` | Remove files |
|
|
238
|
+
| `squash` | `squash` | Interactive rebase squashing |
|
|
239
|
+
| `stage` | `stageManualConflictResolution`, `stageResolvedConflictFiles` | Stage conflict resolutions |
|
|
240
|
+
| `stash` | `getStashes`, `createDesktopStashEntry`, `popStashEntry`, `getStashedFiles`, `dropDesktopStashEntry` | Stash management |
|
|
241
|
+
| `status` | `getStatus` | Repository status |
|
|
242
|
+
| `submodule` | `updateSubmodulesAfterOperation`, `listSubmodules`, `resetSubmodulePaths` | Submodule operations |
|
|
243
|
+
| `tag` | `createTag`, `deleteTag`, `getAllTags` | Tag management |
|
|
244
|
+
| `update-index` | `stageFiles` | Stage files |
|
|
245
|
+
| `update-ref` | `updateRef`, `deleteRef` | Ref updates |
|
|
246
|
+
| `var` | `getAuthorIdentity` | Git var queries |
|
|
247
|
+
| `worktree` | `listWorktrees`, `addWorktree`, `removeWorktree`, `pruneWorktrees`, `getWorktreeCheckedOutBranches` | Worktree management |
|
|
248
|
+
| `worktree-include` | `addWorktreeWithIncludes`, `readWorktreeIncludePatterns` | Worktree with file includes |
|
|
249
|
+
|
|
250
|
+
### Domain Models (`src/models/`)
|
|
251
|
+
|
|
252
|
+
| Export | Type | Description |
|
|
253
|
+
|--------|------|-------------|
|
|
254
|
+
| `Repository` | class | Represents a git repository |
|
|
255
|
+
| `Commit` | class | A single commit (sha, summary, body, author, etc.) |
|
|
256
|
+
| `CommitIdentity` | class | Author/committer identity |
|
|
257
|
+
| `Branch` | class | Branch with upstream tracking info |
|
|
258
|
+
| `BranchType` | enum | `Local` or `Remote` |
|
|
259
|
+
| `AppFileStatusKind` | enum | `New`, `Modified`, `Deleted`, `Renamed`, `Copied`, `Conflicted`, `Untracked` |
|
|
260
|
+
| `FileChange` | class | Base file change model |
|
|
261
|
+
| `WorkingDirectoryFileChange` | class | Uncommitted file change with diff selection |
|
|
262
|
+
| `CommittedFileChange` | class | File change from a commit |
|
|
263
|
+
| `WorkingDirectoryStatus` | class | Container for working directory changes |
|
|
264
|
+
| `DiffSelection` / `DiffSelectionType` | class/enum | Partial file staging |
|
|
265
|
+
| `ComputedAction` | enum | `Clean`, `Conflicts`, `Invalid`, `Loading` |
|
|
266
|
+
| `ManualConflictResolution` | enum | `theirs` / `ours` |
|
|
267
|
+
| `MergeResult` / `RebaseResult` / `CherryPickResult` | enum | Operation outcomes |
|
|
268
|
+
|
|
269
|
+
### Core Types
|
|
270
|
+
|
|
271
|
+
| Export | Description |
|
|
272
|
+
|--------|-------------|
|
|
273
|
+
| `GitError` (class) | Thrown when a git command fails — catch this |
|
|
274
|
+
| `GitErrorCodes` (enum) | Error code constants — `MergeConflicts`, `PushNotFastForward`, `SSHAuthenticationFailed`, etc. (50+ codes) |
|
|
275
|
+
| `IGitResult` | Full command result with `gitError`, `gitErrorDescription`, `path` |
|
|
276
|
+
| `IGitExecutionOptions` | Options for `git()` function |
|
|
277
|
+
|
|
278
|
+
## Known Limitations
|
|
279
|
+
|
|
280
|
+
This library is extracted directly from [GitHub Desktop](https://github.com/desktop/desktop), a mature Electron application. Some subsystems that depend on GitHub Desktop's specific runtime environment have been extracted as **stubs** — they compile and type-check correctly but don't provide real functionality:
|
|
281
|
+
|
|
282
|
+
### 🟡 Progress Reporting (`src/lib/progress/`)
|
|
283
|
+
|
|
284
|
+
The progress parsers (`CheckoutProgressParser`, `FetchProgressParser`, `PullProgressParser`, `PushProgressParser`, `CloneProgressParser`, `RevertProgressParser`) are **stubbed**. Their `parse()` methods always return `null`, and `executionOptionsWithProgress` passes options through unchanged. This means:
|
|
285
|
+
|
|
286
|
+
- Progress callbacks for clone, fetch, push, pull, and checkout will fire the initial `0%` callback but **never receive updates**
|
|
287
|
+
- Long-running operations will complete correctly but without intermediate progress reporting
|
|
288
|
+
|
|
289
|
+
### 🟡 Git Hook Interception (`src/lib/hooks/`)
|
|
290
|
+
|
|
291
|
+
`withHooksEnv` is a **stub** that calls through without configuring any hook environment. The `interceptHooks` option for `git()` and operation functions (e.g., `createCommit`, `push`, `pull`) will **not fire** `onHookProgress` or `onHookFailure` callbacks. Git hooks will still run normally on their own — the library just can't intercept them.
|
|
292
|
+
|
|
293
|
+
### 🟡 Git LFS Trampoline (`src/lib/trampoline/`)
|
|
294
|
+
|
|
295
|
+
`withTrampolineEnv` is a **stub** that calls through without setting up the Git LFS trampoline environment. Git LFS operations may not work correctly as a result.
|
|
296
|
+
|
|
297
|
+
### 🟡 No Tests
|
|
298
|
+
|
|
299
|
+
There are no unit or integration tests yet. While the code is a faithful extraction of the stable GitHub Desktop codebase, there are no automated tests to verify the extraction.
|
|
300
|
+
|
|
301
|
+
### 🟡 Not Published on npm
|
|
302
|
+
|
|
303
|
+
The library is currently available only via git URL or `file:` dependency. No npm release has been published.
|
|
304
|
+
|
|
305
|
+
---
|
|
306
|
+
|
|
43
307
|
## Architecture
|
|
44
308
|
|
|
45
|
-
|
|
309
|
+
```
|
|
310
|
+
src/
|
|
311
|
+
├── index.ts ← Public API entry (barrel)
|
|
312
|
+
├── git/ ← 46 files: one per git subcommand
|
|
313
|
+
│ ├── exec.ts ← Core dugite replacement: spawns git, parses errors
|
|
314
|
+
│ ├── core.ts ← Higher-level git() wrapper with hooks, progress, env
|
|
315
|
+
│ └── index.ts ← Git barrel (re-exports all git modules)
|
|
316
|
+
├── models/ ← 17+ files: domain types
|
|
317
|
+
│ ├── repository.ts
|
|
318
|
+
│ ├── commit.ts
|
|
319
|
+
│ ├── status.ts
|
|
320
|
+
│ ├── diff/ ← Diff types (DiffLine, DiffHunk, IDiff, IRawDiff, etc.)
|
|
321
|
+
│ └── index.ts ← Models barrel
|
|
322
|
+
└── lib/ ← Utilities: parsers, progress reporting, hooks, fs helpers
|
|
323
|
+
├── diff-parser.ts ← Full diff parser (text/binary/image)
|
|
324
|
+
├── status-parser.ts ← Porcelain v2 status parser
|
|
325
|
+
├── progress/ ← 🟡 Progress parsers (stubbed — see Limitations)
|
|
326
|
+
├── hooks/ ← 🟡 Git hook env (stubbed — see Limitations)
|
|
327
|
+
└── trampoline/ ← 🟡 Git LFS trampoline (stubbed — see Limitations)
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
## Development
|
|
46
331
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
332
|
+
```bash
|
|
333
|
+
# Type-check
|
|
334
|
+
npm run typecheck
|
|
335
|
+
|
|
336
|
+
# Build (compile TypeScript → dist/)
|
|
337
|
+
npm run build
|
|
338
|
+
|
|
339
|
+
# Clean rebuild
|
|
340
|
+
rm -rf dist && npm run build
|
|
341
|
+
|
|
342
|
+
# Run examples (uses tsx for source-level execution)
|
|
343
|
+
npx tsx examples/get-status.ts /path/to/repo
|
|
344
|
+
npx tsx examples/branch-operations.ts /path/to/repo
|
|
345
|
+
npx tsx examples/create-commit.ts /path/to/repo
|
|
346
|
+
```
|
|
52
347
|
|
|
53
|
-
###
|
|
348
|
+
### Consumption Notes
|
|
54
349
|
|
|
55
|
-
|
|
56
|
-
-
|
|
57
|
-
- `spawnGit()` — stream-based variant for long-running operations
|
|
58
|
-
- `GitError` enum — 50+ typed Git error codes
|
|
59
|
-
- `parseError()` — maps stderr output to typed errors
|
|
350
|
+
- **Source-level consumption** (recommended for TypeScript projects): Import from `'git-chopstick-core'` — the `exports` field in `package.json` points to TypeScript source. This works with `moduleResolution: "bundler"` in `tsconfig.json`.
|
|
351
|
+
- **Compiled consumption**: Run `npm run build` first, then the compiled output in `dist/` can be imported directly by Node.js ESM.
|
|
60
352
|
|
|
61
353
|
## Dependencies
|
|
62
354
|
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Repository } from '../models/repository.js';
|
|
2
|
+
import { WorkingDirectoryFileChange } from '../models/status.js';
|
|
3
|
+
/**
|
|
4
|
+
* Add a conflicted file to the index.
|
|
5
|
+
*
|
|
6
|
+
* Typically done after having resolved conflicts either manually
|
|
7
|
+
* or through checkout --theirs/--ours.
|
|
8
|
+
*/
|
|
9
|
+
export declare function addConflictedFile(repository: Repository, file: WorkingDirectoryFileChange): Promise<void>;
|
package/dist/git/add.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { git } from './core.js';
|
|
2
|
+
/**
|
|
3
|
+
* Add a conflicted file to the index.
|
|
4
|
+
*
|
|
5
|
+
* Typically done after having resolved conflicts either manually
|
|
6
|
+
* or through checkout --theirs/--ours.
|
|
7
|
+
*/
|
|
8
|
+
export async function addConflictedFile(repository, file) {
|
|
9
|
+
await git(['add', '--', file.path], repository.path, 'addConflictedFile');
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=add.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add.js","sourceRoot":"","sources":["../../src/git/add.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AAI/B;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,UAAsB,EACtB,IAAgC;IAEhC,MAAM,GAAG,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC,IAAI,EAAE,mBAAmB,CAAC,CAAA;AAC3E,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { WorkingDirectoryFileChange } from '../models/status.js';
|
|
2
|
+
import { ITextDiff, DiffSelection } from '../models/diff/index.js';
|
|
3
|
+
import { Repository } from '../models/repository.js';
|
|
4
|
+
export declare function applyPatchToIndex(repository: Repository, file: WorkingDirectoryFileChange): Promise<void>;
|
|
5
|
+
/**
|
|
6
|
+
* Test a patch to see if it will apply cleanly.
|
|
7
|
+
*
|
|
8
|
+
* @param workTree work tree (which should be checked out to a specific commit)
|
|
9
|
+
* @param patch a Git patch (or patch series) to try applying
|
|
10
|
+
* @returns whether the patch applies cleanly
|
|
11
|
+
*
|
|
12
|
+
* See `formatPatch` to generate a patch series from existing Git commits
|
|
13
|
+
*/
|
|
14
|
+
export declare function checkPatch(workTree: {
|
|
15
|
+
path: string;
|
|
16
|
+
}, patch: string): Promise<boolean>;
|
|
17
|
+
/**
|
|
18
|
+
* Discards the local changes for the specified file based on the passed diff
|
|
19
|
+
* and a selection of lines from it.
|
|
20
|
+
*
|
|
21
|
+
* When passed an empty selection, this method won't do anything. When passed a
|
|
22
|
+
* full selection, all changes from the file will be discarded.
|
|
23
|
+
*
|
|
24
|
+
* @param repository The repository in which to update the working directory
|
|
25
|
+
* with information from the index
|
|
26
|
+
*
|
|
27
|
+
* @param filePath The relative path in the working directory of the file to use
|
|
28
|
+
*
|
|
29
|
+
* @param diff The diff containing the file local changes
|
|
30
|
+
*
|
|
31
|
+
* @param selection The selection of changes from the diff to discard
|
|
32
|
+
*/
|
|
33
|
+
export declare function discardChangesFromSelection(repository: Repository, filePath: string, diff: ITextDiff, selection: DiffSelection): Promise<void>;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { GitError as DugiteError } from './exec.js';
|
|
2
|
+
import { git } from './core.js';
|
|
3
|
+
import { WorkingDirectoryFileChange, AppFileStatusKind, } from '../models/status.js';
|
|
4
|
+
import { DiffType } from '../models/diff/index.js';
|
|
5
|
+
import { getWorkingDirectoryDiff } from './diff.js';
|
|
6
|
+
import { formatPatch, formatPatchToDiscardChanges } from '../lib/patch-formatter.js';
|
|
7
|
+
import { assertNever } from '../lib/fatal-error.js';
|
|
8
|
+
export async function applyPatchToIndex(repository, file) {
|
|
9
|
+
// If the file was a rename we have to recreate that rename since we've
|
|
10
|
+
// just blown away the index. Think of this block of weird looking commands
|
|
11
|
+
// as running `git mv`.
|
|
12
|
+
if (file.status.kind === AppFileStatusKind.Renamed) {
|
|
13
|
+
// Make sure the index knows of the removed file. We could use
|
|
14
|
+
// update-index --force-remove here but we're not since it's
|
|
15
|
+
// possible that someone staged a rename and then recreated the
|
|
16
|
+
// original file and we don't have any guarantees for in which order
|
|
17
|
+
// partial stages vs full-file stages happen. By using git add the
|
|
18
|
+
// worst that could happen is that we re-stage a file already staged
|
|
19
|
+
// by updateIndex.
|
|
20
|
+
await git(['add', '--update', '--', file.status.oldPath], repository.path, 'applyPatchToIndex');
|
|
21
|
+
// Figure out the blob oid of the removed file
|
|
22
|
+
// <mode> SP <type> SP <object> TAB <file>
|
|
23
|
+
const oldFile = await git(['ls-tree', 'HEAD', '--', file.status.oldPath], repository.path, 'applyPatchToIndex');
|
|
24
|
+
const [info] = oldFile.stdout.split('\t', 1);
|
|
25
|
+
const [mode, , oid] = info.split(' ', 3);
|
|
26
|
+
// Add the old file blob to the index under the new name
|
|
27
|
+
await git(['update-index', '--add', '--cacheinfo', mode, oid, file.path], repository.path, 'applyPatchToIndex');
|
|
28
|
+
}
|
|
29
|
+
const applyArgs = [
|
|
30
|
+
'apply',
|
|
31
|
+
'--cached',
|
|
32
|
+
'--unidiff-zero',
|
|
33
|
+
'--whitespace=nowarn',
|
|
34
|
+
'-',
|
|
35
|
+
];
|
|
36
|
+
const diff = await getWorkingDirectoryDiff(repository, file);
|
|
37
|
+
if (diff.kind !== DiffType.Text && diff.kind !== DiffType.LargeText) {
|
|
38
|
+
const { kind } = diff;
|
|
39
|
+
switch (diff.kind) {
|
|
40
|
+
case DiffType.Binary:
|
|
41
|
+
case DiffType.Submodule:
|
|
42
|
+
case DiffType.Image:
|
|
43
|
+
throw new Error(`Can't create partial commit in binary file: ${file.path}`);
|
|
44
|
+
case DiffType.Unrenderable:
|
|
45
|
+
throw new Error(`File diff is too large to generate a partial commit: ${file.path}`);
|
|
46
|
+
default:
|
|
47
|
+
assertNever(diff, `Unknown diff kind: ${kind}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const patch = await formatPatch(repository, file, file.selection);
|
|
51
|
+
await git(applyArgs, repository.path, 'applyPatchToIndex', { stdin: patch });
|
|
52
|
+
return Promise.resolve();
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Test a patch to see if it will apply cleanly.
|
|
56
|
+
*
|
|
57
|
+
* @param workTree work tree (which should be checked out to a specific commit)
|
|
58
|
+
* @param patch a Git patch (or patch series) to try applying
|
|
59
|
+
* @returns whether the patch applies cleanly
|
|
60
|
+
*
|
|
61
|
+
* See `formatPatch` to generate a patch series from existing Git commits
|
|
62
|
+
*/
|
|
63
|
+
export async function checkPatch(workTree, patch) {
|
|
64
|
+
const result = await git(['apply', '--check', '-'], workTree.path, 'checkPatch', {
|
|
65
|
+
stdin: patch,
|
|
66
|
+
encoding: 'utf8',
|
|
67
|
+
expectedErrors: new Set([DugiteError.PatchDoesNotApply]),
|
|
68
|
+
});
|
|
69
|
+
if (result.gitError === DugiteError.PatchDoesNotApply) {
|
|
70
|
+
// other errors will be thrown if encountered, so this is fine for now
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Discards the local changes for the specified file based on the passed diff
|
|
77
|
+
* and a selection of lines from it.
|
|
78
|
+
*
|
|
79
|
+
* When passed an empty selection, this method won't do anything. When passed a
|
|
80
|
+
* full selection, all changes from the file will be discarded.
|
|
81
|
+
*
|
|
82
|
+
* @param repository The repository in which to update the working directory
|
|
83
|
+
* with information from the index
|
|
84
|
+
*
|
|
85
|
+
* @param filePath The relative path in the working directory of the file to use
|
|
86
|
+
*
|
|
87
|
+
* @param diff The diff containing the file local changes
|
|
88
|
+
*
|
|
89
|
+
* @param selection The selection of changes from the diff to discard
|
|
90
|
+
*/
|
|
91
|
+
export async function discardChangesFromSelection(repository, filePath, diff, selection) {
|
|
92
|
+
const file = new WorkingDirectoryFileChange(filePath, { kind: AppFileStatusKind.Modified }, selection);
|
|
93
|
+
const patch = await formatPatchToDiscardChanges(repository, file);
|
|
94
|
+
if (patch === null || patch === '') {
|
|
95
|
+
// When the patch is null we don't need to apply it since it will be a noop.
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const args = ['apply', '--unidiff-zero', '--whitespace=nowarn', '-'];
|
|
99
|
+
await git(args, repository.path, 'discardChangesFromSelection', {
|
|
100
|
+
stdin: patch,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=apply.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply.js","sourceRoot":"","sources":["../../src/git/apply.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { GitError as DugiteError } from './exec.js';
|
|
2
|
+
/** Get the environment for authenticating remote operations. */
|
|
3
|
+
export declare function envForAuthentication(): Record<string, string | undefined>;
|
|
4
|
+
/** The set of errors which fit under the "authentication failed" umbrella. */
|
|
5
|
+
export declare const AuthenticationErrors: ReadonlySet<DugiteError>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { GitError as DugiteError } from './exec.js';
|
|
2
|
+
/** Get the environment for authenticating remote operations. */
|
|
3
|
+
export function envForAuthentication() {
|
|
4
|
+
return {
|
|
5
|
+
// supported since Git 2.3, this is used to ensure we never interactively prompt
|
|
6
|
+
// for credentials - even as a fallback
|
|
7
|
+
GIT_TERMINAL_PROMPT: '0',
|
|
8
|
+
// localStorage is not available in Node.js; fall back to process.env
|
|
9
|
+
GIT_TRACE: process.env.GIT_TRACE ?? '0',
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
/** The set of errors which fit under the "authentication failed" umbrella. */
|
|
13
|
+
export const AuthenticationErrors = new Set([
|
|
14
|
+
DugiteError.HTTPSAuthenticationFailed,
|
|
15
|
+
DugiteError.SSHAuthenticationFailed,
|
|
16
|
+
DugiteError.HTTPSRepositoryNotFound,
|
|
17
|
+
DugiteError.SSHRepositoryNotFound,
|
|
18
|
+
]);
|
|
19
|
+
//# sourceMappingURL=authentication.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authentication.js","sourceRoot":"","sources":["../../src/git/authentication.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,WAAW,EAAE,MAAM,WAAW,CAAA;AAEnD,gEAAgE;AAChE,MAAM,UAAU,oBAAoB;IAClC,OAAO;QACL,gFAAgF;QAChF,uCAAuC;QACvC,mBAAmB,EAAE,GAAG;QACxB,qEAAqE;QACrE,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,GAAG;KACxC,CAAA;AACH,CAAC;AAED,8EAA8E;AAC9E,MAAM,CAAC,MAAM,oBAAoB,GAA6B,IAAI,GAAG,CAAC;IACpE,WAAW,CAAC,yBAAyB;IACrC,WAAW,CAAC,uBAAuB;IACnC,WAAW,CAAC,uBAAuB;IACnC,WAAW,CAAC,qBAAqB;CAClC,CAAC,CAAA"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Repository } from '../models/repository.js';
|
|
2
|
+
import { Branch } from '../models/branch.js';
|
|
3
|
+
import { IRemote } from '../models/remote.js';
|
|
4
|
+
/**
|
|
5
|
+
* Create a new branch from the given start point.
|
|
6
|
+
*
|
|
7
|
+
* @param repository - The repository in which to create the new branch
|
|
8
|
+
* @param name - The name of the new branch
|
|
9
|
+
* @param startPoint - A committish string that the new branch should be based
|
|
10
|
+
* on, or undefined if the branch should be created based
|
|
11
|
+
* off of the current state of HEAD
|
|
12
|
+
*/
|
|
13
|
+
export declare function createBranch(repository: Repository, name: string, startPoint: string | null, noTrack?: boolean): Promise<void>;
|
|
14
|
+
export declare const getBranchNames: ({ path }: Repository) => Promise<string[]>;
|
|
15
|
+
/** Rename the given branch to a new name. */
|
|
16
|
+
export declare function renameBranch(repository: Repository, branch: Branch, newName: string, force?: boolean): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Delete the branch locally.
|
|
19
|
+
*/
|
|
20
|
+
export declare function deleteLocalBranch(repository: Repository, branchName: string): Promise<true>;
|
|
21
|
+
/**
|
|
22
|
+
* Deletes a remote branch
|
|
23
|
+
*
|
|
24
|
+
* @param remoteName - the name of the remote to delete the branch from
|
|
25
|
+
* @param remoteBranchName - the name of the branch on the remote
|
|
26
|
+
*/
|
|
27
|
+
export declare function deleteRemoteBranch(repository: Repository, remote: IRemote, remoteBranchName: string): Promise<true>;
|
|
28
|
+
/**
|
|
29
|
+
* Finds branches that have a tip equal to the given committish
|
|
30
|
+
*
|
|
31
|
+
* @param repository within which to execute the command
|
|
32
|
+
* @param commitish a sha, HEAD, etc that the branch(es) tip should be
|
|
33
|
+
* @returns list branch names. null if an error is encountered
|
|
34
|
+
*/
|
|
35
|
+
export declare function getBranchesPointedAt(repository: Repository, commitish: string): Promise<Array<string> | null>;
|
|
36
|
+
/**
|
|
37
|
+
* Gets all branches that have been merged into the given branch
|
|
38
|
+
*
|
|
39
|
+
* @param repository The repository in which to search
|
|
40
|
+
* @param branchName The to be used as the base branch
|
|
41
|
+
* @returns map of branch canonical refs paired to its sha
|
|
42
|
+
*/
|
|
43
|
+
export declare function getMergedBranches(repository: Repository, branchName: string): Promise<Map<string, string>>;
|