MCPcopy Index your code
hub / github.com/21st-dev/1code / getLocalBranchesWithDates

Function getLocalBranchesWithDates

src/main/lib/git/branches.ts:269–298  ·  view source on GitHub ↗
(
	git: ReturnType<typeof simpleGit>,
	localBranches: string[],
)

Source from the content-addressed store, hash-verified

267};
268
269async function getLocalBranchesWithDates(
270 git: ReturnType<typeof simpleGit>,
271 localBranches: string[],
272): Promise<Array<{ branch: string; lastCommitDate: number }>> {
273 try {
274 const branchInfo = await git.raw([
275 "for-each-ref",
276 "--sort=-committerdate",
277 "--format=%(refname:short) %(committerdate:unix)",
278 "refs/heads/",
279 ]);
280
281 const local: Array<{ branch: string; lastCommitDate: number }> = [];
282 for (const line of branchInfo.trim().split("\n")) {
283 if (!line) continue;
284 const lastSpaceIdx = line.lastIndexOf(" ");
285 const branch = line.substring(0, lastSpaceIdx);
286 const timestamp = Number.parseInt(line.substring(lastSpaceIdx + 1), 10);
287 if (localBranches.includes(branch)) {
288 local.push({
289 branch,
290 lastCommitDate: timestamp * 1000,
291 });
292 }
293 }
294 return local;
295 } catch {
296 return localBranches.map((branch) => ({ branch, lastCommitDate: 0 }));
297 }
298}
299
300async function getDefaultBranch(
301 git: ReturnType<typeof simpleGit>,

Callers 1

createBranchesRouterFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected