MCPcopy Index your code
hub / github.com/codeaashu/claude-code / detectGitOperation

Function detectGitOperation

src/tools/shared/gitOperationTracking.ts:135–186  ·  view source on GitHub ↗
(
  command: string,
  output: string,
)

Source from the content-addressed store, hash-verified

133 * Pass stdout+stderr concatenated — git push writes the ref update to stderr.
134 */
135export function detectGitOperation(
136 command: string,
137 output: string,
138): {
139 commit?: { sha: string; kind: CommitKind }
140 push?: { branch: string }
141 branch?: { ref: string; action: BranchAction }
142 pr?: { number: number; url?: string; action: PrAction }
143} {
144 const result: ReturnType<typeof detectGitOperation> = {}
145 // commit and cherry-pick both produce "[branch sha] msg" output
146 const isCherryPick = GIT_CHERRY_PICK_RE.test(command)
147 if (GIT_COMMIT_RE.test(command) || isCherryPick) {
148 const sha = parseGitCommitId(output)
149 if (sha) {
150 result.commit = {
151 sha: sha.slice(0, 6),
152 kind: isCherryPick
153 ? 'cherry-picked'
154 : /--amend\b/.test(command)
155 ? 'amended'
156 : 'committed',
157 }
158 }
159 }
160 if (GIT_PUSH_RE.test(command)) {
161 const branch = parseGitPushBranch(output)
162 if (branch) result.push = { branch }
163 }
164 if (
165 GIT_MERGE_RE.test(command) &&
166 /(Fast-forward|Merge made by)/.test(output)
167 ) {
168 const ref = parseRefFromCommand(command, 'merge')
169 if (ref) result.branch = { ref, action: 'merged' }
170 }
171 if (GIT_REBASE_RE.test(command) && /Successfully rebased/.test(output)) {
172 const ref = parseRefFromCommand(command, 'rebase')
173 if (ref) result.branch = { ref, action: 'rebased' }
174 }
175 const prAction = GH_PR_ACTIONS.find(a => a.re.test(command))?.action
176 if (prAction) {
177 const pr = findPrInStdout(output)
178 if (pr) {
179 result.pr = { number: pr.prNumber, url: pr.prUrl, action: prAction }
180 } else {
181 const num = parsePrNumberFromText(output)
182 if (num) result.pr = { number: num, action: prAction }
183 }
184 }
185 return result
186}
187
188// Exported for testing purposes
189export function trackGitOperations(

Callers 1

scanBashResultForGitOpsFunction · 0.85

Calls 5

parseGitCommitIdFunction · 0.85
parseGitPushBranchFunction · 0.85
parseRefFromCommandFunction · 0.85
findPrInStdoutFunction · 0.85
parsePrNumberFromTextFunction · 0.85

Tested by

no test coverage detected