git-chopstick-core 0.1.2 → 0.1.3

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.
Files changed (128) hide show
  1. package/README.md +6 -6
  2. package/dist/git/exec.js.map +1 -1
  3. package/dist/lib/fatal-error.d.ts +1 -1
  4. package/dist/lib/fatal-error.js +1 -1
  5. package/dist/lib/fatal-error.js.map +1 -1
  6. package/dist/lib/progress/from-process.js.map +1 -1
  7. package/dist/lib/progress/index.d.ts +5 -5
  8. package/dist/lib/progress/index.js +5 -5
  9. package/dist/lib/progress/index.js.map +1 -1
  10. package/dist/lib/status-parser.js +0 -12
  11. package/dist/lib/status-parser.js.map +1 -1
  12. package/package.json +38 -8
  13. package/src/git/add.ts +0 -16
  14. package/src/git/apply.ts +0 -154
  15. package/src/git/authentication.ts +0 -20
  16. package/src/git/branch.ts +0 -206
  17. package/src/git/checkout-index.ts +0 -40
  18. package/src/git/checkout.ts +0 -235
  19. package/src/git/cherry-pick.ts +0 -504
  20. package/src/git/clean.ts +0 -9
  21. package/src/git/clone.ts +0 -86
  22. package/src/git/coerce-to-buffer.ts +0 -4
  23. package/src/git/coerce-to-string.ts +0 -4
  24. package/src/git/commit.ts +0 -136
  25. package/src/git/config.ts +0 -392
  26. package/src/git/core.ts +0 -625
  27. package/src/git/create-tail-stream.ts +0 -36
  28. package/src/git/credential.ts +0 -83
  29. package/src/git/description.ts +0 -33
  30. package/src/git/diff-check.ts +0 -27
  31. package/src/git/diff-index.ts +0 -116
  32. package/src/git/diff.ts +0 -880
  33. package/src/git/environment.ts +0 -116
  34. package/src/git/exec.ts +0 -285
  35. package/src/git/fetch.ts +0 -141
  36. package/src/git/for-each-ref.ts +0 -160
  37. package/src/git/format-patch.ts +0 -17
  38. package/src/git/git-delimiter-parser.ts +0 -95
  39. package/src/git/gitignore.ts +0 -157
  40. package/src/git/index.ts +0 -46
  41. package/src/git/init.ts +0 -11
  42. package/src/git/interpret-trailers.ts +0 -176
  43. package/src/git/lfs.ts +0 -100
  44. package/src/git/log.ts +0 -376
  45. package/src/git/merge-tree.ts +0 -42
  46. package/src/git/merge.ts +0 -154
  47. package/src/git/multi-operation-terminal-output.ts +0 -68
  48. package/src/git/pull.ts +0 -130
  49. package/src/git/push-terminal-chunk.ts +0 -41
  50. package/src/git/push.ts +0 -119
  51. package/src/git/rebase.ts +0 -627
  52. package/src/git/reflog.ts +0 -127
  53. package/src/git/refs.ts +0 -63
  54. package/src/git/remote.ts +0 -143
  55. package/src/git/reorder.ts +0 -153
  56. package/src/git/reset.ts +0 -101
  57. package/src/git/rev-list.ts +0 -201
  58. package/src/git/rev-parse.ts +0 -92
  59. package/src/git/revert.ts +0 -55
  60. package/src/git/rm.ts +0 -31
  61. package/src/git/show.ts +0 -88
  62. package/src/git/spawn.ts +0 -38
  63. package/src/git/squash.ts +0 -173
  64. package/src/git/stage.ts +0 -97
  65. package/src/git/stash.ts +0 -302
  66. package/src/git/status.ts +0 -502
  67. package/src/git/submodule.ts +0 -212
  68. package/src/git/tag.ts +0 -134
  69. package/src/git/update-index.ts +0 -169
  70. package/src/git/update-ref.ts +0 -50
  71. package/src/git/var.ts +0 -42
  72. package/src/git/worktree-include.ts +0 -146
  73. package/src/git/worktree.ts +0 -219
  74. package/src/index.ts +0 -11
  75. package/src/lib/api.ts +0 -7
  76. package/src/lib/diff-parser.ts +0 -249
  77. package/src/lib/directory-exists.ts +0 -10
  78. package/src/lib/errno-exception.ts +0 -12
  79. package/src/lib/fatal-error.ts +0 -23
  80. package/src/lib/feature-flag.ts +0 -29
  81. package/src/lib/file-system.ts +0 -7
  82. package/src/lib/get-old-path.ts +0 -11
  83. package/src/lib/git/environment.ts +0 -14
  84. package/src/lib/git-perf.ts +0 -3
  85. package/src/lib/helpers/default-branch.ts +0 -3
  86. package/src/lib/helpers/path.ts +0 -5
  87. package/src/lib/hooks/with-hooks-env.ts +0 -7
  88. package/src/lib/merge.ts +0 -3
  89. package/src/lib/noop.ts +0 -1
  90. package/src/lib/patch-formatter.ts +0 -18
  91. package/src/lib/path-exists.ts +0 -7
  92. package/src/lib/progress/from-process.ts +0 -10
  93. package/src/lib/progress/index.ts +0 -43
  94. package/src/lib/progress/revert.ts +0 -17
  95. package/src/lib/rebase.ts +0 -3
  96. package/src/lib/remove-remote-prefix.ts +0 -4
  97. package/src/lib/resolve-git-proxy.ts +0 -3
  98. package/src/lib/round.ts +0 -4
  99. package/src/lib/split-buffer.ts +0 -14
  100. package/src/lib/status-parser.ts +0 -188
  101. package/src/lib/stores/helpers/find-default-remote.ts +0 -3
  102. package/src/lib/trampoline/trampoline-environment.ts +0 -8
  103. package/src/models/branch.ts +0 -78
  104. package/src/models/cherry-pick.ts +0 -12
  105. package/src/models/clone-options.ts +0 -6
  106. package/src/models/commit-identity.ts +0 -35
  107. package/src/models/commit.ts +0 -44
  108. package/src/models/computed-action.ts +0 -6
  109. package/src/models/diff/diff-data.ts +0 -78
  110. package/src/models/diff/diff-line.ts +0 -36
  111. package/src/models/diff/diff-selection.ts +0 -165
  112. package/src/models/diff/image-diff.ts +0 -6
  113. package/src/models/diff/image.ts +0 -8
  114. package/src/models/diff/index.ts +0 -6
  115. package/src/models/diff/raw-diff.ts +0 -41
  116. package/src/models/git-author.ts +0 -16
  117. package/src/models/index.ts +0 -36
  118. package/src/models/manual-conflict-resolution.ts +0 -4
  119. package/src/models/merge.ts +0 -6
  120. package/src/models/multi-commit-operation.ts +0 -6
  121. package/src/models/progress.ts +0 -67
  122. package/src/models/rebase.ts +0 -20
  123. package/src/models/remote.ts +0 -10
  124. package/src/models/repository.ts +0 -16
  125. package/src/models/stash-entry.ts +0 -25
  126. package/src/models/status.ts +0 -275
  127. package/src/models/submodule.ts +0 -13
  128. package/src/models/worktree.ts +0 -11
package/src/git/branch.ts DELETED
@@ -1,206 +0,0 @@
1
- import { git, isGitError } from './core.js'
2
- import { Repository } from '../models/repository.js'
3
- import { Branch } from '../models/branch.js'
4
- import { formatAsLocalRef } from './refs.js'
5
- import { deleteRef } from './update-ref.js'
6
- import { GitError as DugiteError } from './exec.js'
7
- import { envForRemoteOperation } from './environment.js'
8
- import { createForEachRefParser } from './git-delimiter-parser.js'
9
- import { IRemote } from '../models/remote.js'
10
- import { coerceToString } from './coerce-to-string.js'
11
-
12
- /**
13
- * Create a new branch from the given start point.
14
- *
15
- * @param repository - The repository in which to create the new branch
16
- * @param name - The name of the new branch
17
- * @param startPoint - A committish string that the new branch should be based
18
- * on, or undefined if the branch should be created based
19
- * off of the current state of HEAD
20
- */
21
- export async function createBranch(
22
- repository: Repository,
23
- name: string,
24
- startPoint: string | null,
25
- noTrack?: boolean
26
- ): Promise<void> {
27
- const args =
28
- startPoint !== null ? ['branch', name, startPoint] : ['branch', name]
29
-
30
- // if we're branching directly from a remote branch, we don't want to track it
31
- // tracking it will make the rest of desktop think we want to push to that
32
- // remote branch's upstream (which would likely be the upstream of the fork)
33
- if (noTrack) {
34
- args.push('--no-track')
35
- }
36
-
37
- await git(args, repository.path, 'createBranch')
38
- }
39
-
40
- export const getBranchNames = ({ path }: Repository): Promise<string[]> => {
41
- const parser = createForEachRefParser({ name: '%(refname:short)' })
42
- return git(['branch', ...parser.formatArgs], path, 'getBranchNames').then(x =>
43
- parser.parse(x.stdout).map(b => b.name)
44
- )
45
- }
46
-
47
- /** Rename the given branch to a new name. */
48
- export async function renameBranch(
49
- repository: Repository,
50
- branch: Branch,
51
- newName: string,
52
- force?: boolean
53
- ): Promise<void> {
54
- try {
55
- await git(
56
- ['branch', force ? '-M' : '-m', branch.nameWithoutRemote, newName],
57
- repository.path,
58
- 'renameBranch'
59
- )
60
- } catch (error) {
61
- // If we failed to rename and the branch name only differs by case, we
62
- // we'll try again with the -M flag to force the rename. See
63
- // https://github.com/desktop/desktop/issues/21320
64
- if (
65
- // Only retry if the caller hasn't explicitly asked us to force the rename
66
- force === undefined &&
67
- isGitError(error) &&
68
- error.result.gitError === DugiteError.BranchAlreadyExists
69
- ) {
70
- const stderr = coerceToString(error.result.stderr)
71
- const m = /fatal: a branch named '(.+?)' already exists/.exec(stderr)
72
-
73
- if (m && m[1].toLowerCase() === newName.toLowerCase()) {
74
- // At this point we're almost certain that we are dealing with a
75
- // case-only rename on a case insensitive filesystem, but we can't
76
- // be 100% sure, NTFS can be configured to be case sensitive and macOS
77
- // might have case sensitive file systems mounted so we have to list
78
- // all branches and check the names.
79
- return (
80
- getBranchNames(repository)
81
- // Throw the original error if we fail to get the branch names
82
- .catch(() => Promise.reject(error))
83
- .then(names =>
84
- // If we find the new name in the list of branches we can't
85
- // safely assume it's a case-only rename and have to
86
- // propagate the original error, otherwise try again with -M
87
- names.includes(newName)
88
- ? Promise.reject(error)
89
- : renameBranch(repository, branch, newName, true)
90
- )
91
- )
92
- }
93
- }
94
- throw error
95
- }
96
- }
97
-
98
- /**
99
- * Delete the branch locally.
100
- */
101
- export async function deleteLocalBranch(
102
- repository: Repository,
103
- branchName: string
104
- ): Promise<true> {
105
- await git(['branch', '-D', branchName], repository.path, 'deleteLocalBranch')
106
- return true
107
- }
108
-
109
- /**
110
- * Deletes a remote branch
111
- *
112
- * @param remoteName - the name of the remote to delete the branch from
113
- * @param remoteBranchName - the name of the branch on the remote
114
- */
115
- export async function deleteRemoteBranch(
116
- repository: Repository,
117
- remote: IRemote,
118
- remoteBranchName: string
119
- ): Promise<true> {
120
- const args = ['push', remote.name, `:${remoteBranchName}`]
121
-
122
- // If the user is not authenticated, the push is going to fail
123
- // Let this propagate and leave it to the caller to handle
124
- const result = await git(args, repository.path, 'deleteRemoteBranch', {
125
- env: await envForRemoteOperation(remote.url),
126
- expectedErrors: new Set<DugiteError>([DugiteError.BranchDeletionFailed]),
127
- })
128
-
129
- // It's possible that the delete failed because the ref has already
130
- // been deleted on the remote. If we identify that specific
131
- // error we can safely remove our remote ref which is what would
132
- // happen if the push didn't fail.
133
- if (result.gitError === DugiteError.BranchDeletionFailed) {
134
- const ref = `refs/remotes/${remote.name}/${remoteBranchName}`
135
- await deleteRef(repository, ref)
136
- }
137
-
138
- return true
139
- }
140
-
141
- /**
142
- * Finds branches that have a tip equal to the given committish
143
- *
144
- * @param repository within which to execute the command
145
- * @param commitish a sha, HEAD, etc that the branch(es) tip should be
146
- * @returns list branch names. null if an error is encountered
147
- */
148
- export async function getBranchesPointedAt(
149
- repository: Repository,
150
- commitish: string
151
- ): Promise<Array<string> | null> {
152
- const args = [
153
- 'branch',
154
- `--points-at=${commitish}`,
155
- '--format=%(refname:short)',
156
- ]
157
- // this command has an implicit \n delimiter
158
- const { stdout, exitCode } = await git(
159
- args,
160
- repository.path,
161
- 'branchPointedAt',
162
- {
163
- // - 1 is returned if a common ancestor cannot be resolved
164
- // - 129 is returned if ref is malformed
165
- // "warning: ignoring broken ref refs/remotes/origin/main."
166
- successExitCodes: new Set([0, 1, 129]),
167
- }
168
- )
169
- if (exitCode === 1 || exitCode === 129) {
170
- return null
171
- }
172
- // split (and remove trailing element cause its always an empty string)
173
- return stdout.split('\n').slice(0, -1)
174
- }
175
-
176
- /**
177
- * Gets all branches that have been merged into the given branch
178
- *
179
- * @param repository The repository in which to search
180
- * @param branchName The to be used as the base branch
181
- * @returns map of branch canonical refs paired to its sha
182
- */
183
- export async function getMergedBranches(
184
- repository: Repository,
185
- branchName: string
186
- ): Promise<Map<string, string>> {
187
- const canonicalBranchRef = formatAsLocalRef(branchName)
188
- const { formatArgs, parse } = createForEachRefParser({
189
- sha: '%(objectname)',
190
- canonicalRef: '%(refname)',
191
- })
192
-
193
- const args = ['branch', ...formatArgs, '--merged', branchName]
194
- const mergedBranches = new Map<string, string>()
195
- const { stdout } = await git(args, repository.path, 'mergedBranches')
196
-
197
- for (const branch of parse(stdout)) {
198
- // Don't include the branch we're using to compare against
199
- // in the list of branches merged into that branch.
200
- if (branch.canonicalRef !== canonicalBranchRef) {
201
- mergedBranches.set(branch.canonicalRef, branch.sha)
202
- }
203
- }
204
-
205
- return mergedBranches
206
- }
@@ -1,40 +0,0 @@
1
- import { git } from './core.js'
2
- import { Repository } from '../models/repository.js'
3
-
4
- /**
5
- * Forcefully updates the working directory with information from the index
6
- * for a given set of files.
7
- *
8
- * This method is essentially the same as running `git checkout -- files`
9
- * except by using `checkout-index` we can pass the files we want updated
10
- * on stdin, avoiding all issues with too long arguments.
11
- *
12
- * Note that this function will not yield errors for paths that don't
13
- * exist in the index (-q).
14
- *
15
- * @param repository The repository in which to update the working directory
16
- * with information from the index
17
- *
18
- * @param paths The relative paths in the working directory to update
19
- * with information from the index.
20
- */
21
- export async function checkoutIndex(
22
- repository: Repository,
23
- paths: ReadonlyArray<string>
24
- ) {
25
- if (!paths.length) {
26
- return
27
- }
28
-
29
- const options = {
30
- successExitCodes: new Set([0, 1]),
31
- stdin: paths.join('\0'),
32
- }
33
-
34
- await git(
35
- ['checkout-index', '-f', '-u', '-q', '--stdin', '-z'],
36
- repository.path,
37
- 'checkoutIndex',
38
- options
39
- )
40
- }
@@ -1,235 +0,0 @@
1
- import { git, IGitStringExecutionOptions } from './core.js'
2
- import { Repository } from '../models/repository.js'
3
- import { Branch, BranchType } from '../models/branch.js'
4
- import { clampProgress, ICheckoutProgress } from '../models/progress.js'
5
- import {
6
- CheckoutProgressParser,
7
- executionOptionsWithProgress,
8
- } from '../lib/progress/index.js'
9
- import { AuthenticationErrors } from './authentication.js'
10
- import {
11
- envForRemoteOperation,
12
- getFallbackUrlForProxyResolve,
13
- } from './environment.js'
14
- import { WorkingDirectoryFileChange } from '../models/status.js'
15
- import { ManualConflictResolution } from '../models/manual-conflict-resolution.js'
16
- import { CommitOneLine, shortenSHA } from '../models/commit.js'
17
- import { IRemote } from '../models/remote.js'
18
- import { updateSubmodulesAfterOperation } from './submodule.js'
19
-
20
- export type ProgressCallback = (progress: ICheckoutProgress) => void
21
-
22
- const CheckoutStepWeight = 0.9
23
-
24
- function getCheckoutArgs(progressCallback?: ProgressCallback) {
25
- return ['checkout', ...(progressCallback ? ['--progress'] : [])]
26
- }
27
-
28
- async function getBranchCheckoutArgs(branch: Branch) {
29
- return [
30
- branch.name,
31
- ...(branch.type === BranchType.Remote
32
- ? ['-b', branch.nameWithoutRemote]
33
- : []),
34
- '--',
35
- ]
36
- }
37
-
38
- async function getCheckoutOpts(
39
- repository: Repository,
40
- title: string,
41
- target: string,
42
- currentRemote: IRemote | null,
43
- progressCallback?: ProgressCallback,
44
- initialDescription?: string
45
- ): Promise<IGitStringExecutionOptions> {
46
- const opts: IGitStringExecutionOptions = {
47
- env: await envForRemoteOperation(
48
- getFallbackUrlForProxyResolve(repository, currentRemote)
49
- ),
50
- expectedErrors: AuthenticationErrors,
51
- }
52
-
53
- if (!progressCallback) {
54
- return opts
55
- }
56
-
57
- const kind = 'checkout'
58
-
59
- // Initial progress
60
- progressCallback({
61
- kind,
62
- title,
63
- description: initialDescription ?? title,
64
- value: 0,
65
- target,
66
- })
67
-
68
- return await executionOptionsWithProgress(
69
- { ...opts, trackLFSProgress: true },
70
- new CheckoutProgressParser(),
71
- progress => {
72
- if (progress.kind === 'progress') {
73
- const description = progress.details.text
74
- const value = progress.percent
75
-
76
- progressCallback({
77
- kind,
78
- title,
79
- description,
80
- value,
81
- target,
82
- })
83
- }
84
- }
85
- )
86
- }
87
-
88
- /**
89
- * Check out the given branch.
90
- *
91
- * @param repository - The repository in which the branch checkout should
92
- * take place
93
- *
94
- * @param branch - The branch name that should be checked out
95
- *
96
- * @param progressCallback - An optional function which will be invoked
97
- * with information about the current progress
98
- * of the checkout operation. When provided this
99
- * enables the '--progress' command line flag for
100
- * 'git checkout'.
101
- */
102
- export async function checkoutBranch(
103
- repository: Repository,
104
- branch: Branch,
105
- currentRemote: IRemote | null,
106
- progressCallback?: ProgressCallback,
107
- allowFileProtocol: boolean = false
108
- ): Promise<true> {
109
- const title = `Checking out branch ${branch.name}`
110
- const opts = await getCheckoutOpts(
111
- repository,
112
- title,
113
- branch.name,
114
- currentRemote,
115
- progressCallback
116
- ? clampProgress(0, CheckoutStepWeight, progressCallback)
117
- : undefined,
118
- `Switching to branch`
119
- )
120
-
121
- const baseArgs = getCheckoutArgs(progressCallback)
122
- const args = [...baseArgs, ...(await getBranchCheckoutArgs(branch))]
123
-
124
- await git(args, repository.path, 'checkoutBranch', opts)
125
-
126
- // Update submodules after checkout
127
- await updateSubmodulesAfterOperation(
128
- repository,
129
- currentRemote,
130
- progressCallback
131
- ? clampProgress<ICheckoutProgress>(
132
- CheckoutStepWeight,
133
- 1,
134
- progressCallback
135
- )
136
- : undefined,
137
- 'checkout',
138
- title,
139
- branch.name,
140
- allowFileProtocol
141
- )
142
-
143
- // we return `true` here so `GitStore.performFailableGitOperation`
144
- // will return _something_ differentiable from `undefined` if this succeeds
145
- return true
146
- }
147
-
148
- /**
149
- * Check out the given commit.
150
- * Literally invokes `git checkout <commit SHA>`.
151
- *
152
- * @param repository - The repository in which the branch checkout should
153
- * take place
154
- *
155
- * @param commit - The commit that should be checked out
156
- *
157
- * @param progressCallback - An optional function which will be invoked
158
- * with information about the current progress
159
- * of the checkout operation. When provided this
160
- * enables the '--progress' command line flag for
161
- * 'git checkout'.
162
- */
163
- export async function checkoutCommit(
164
- repository: Repository,
165
- commit: CommitOneLine,
166
- currentRemote: IRemote | null,
167
- progressCallback?: ProgressCallback,
168
- allowFileProtocol: boolean = false
169
- ): Promise<true> {
170
- const title = `Checking out commit`
171
- const target = shortenSHA(commit.sha)
172
- const opts = await getCheckoutOpts(
173
- repository,
174
- title,
175
- target,
176
- currentRemote,
177
- progressCallback
178
- ? clampProgress(0, CheckoutStepWeight, progressCallback)
179
- : undefined
180
- )
181
-
182
- const baseArgs = getCheckoutArgs(progressCallback)
183
- const args = [...baseArgs, commit.sha]
184
-
185
- await git(args, repository.path, 'checkoutCommit', opts)
186
-
187
- // Update submodules after checkout
188
- await updateSubmodulesAfterOperation(
189
- repository,
190
- currentRemote,
191
- progressCallback
192
- ? clampProgress<ICheckoutProgress>(
193
- CheckoutStepWeight,
194
- 1,
195
- progressCallback
196
- )
197
- : undefined,
198
- 'checkout',
199
- title,
200
- target,
201
- allowFileProtocol
202
- )
203
-
204
- // we return `true` here so `GitStore.performFailableGitOperation`
205
- // will return _something_ differentiable from `undefined` if this succeeds
206
- return true
207
- }
208
-
209
- /** Check out the paths at HEAD. */
210
- export async function checkoutPaths(
211
- repository: Repository,
212
- paths: ReadonlyArray<string>
213
- ): Promise<void> {
214
- await git(
215
- ['checkout', 'HEAD', '--', ...paths],
216
- repository.path,
217
- 'checkoutPaths'
218
- )
219
- }
220
-
221
- /**
222
- * Check out either stage #2 (ours) or #3 (theirs) for a conflicted
223
- * file.
224
- */
225
- export async function checkoutConflictedFile(
226
- repository: Repository,
227
- file: WorkingDirectoryFileChange,
228
- resolution: ManualConflictResolution
229
- ) {
230
- await git(
231
- ['checkout', `--${resolution}`, '--', file.path],
232
- repository.path,
233
- 'checkoutConflictedFile'
234
- )
235
- }