gitpt 1.4.0 → 1.7.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.
Files changed (116) hide show
  1. package/README.md +34 -160
  2. package/dist/commands/commit/commitFlags.js +7 -0
  3. package/dist/commands/commit/context/buildPrompt.js +16 -0
  4. package/dist/commands/commit/context/summaryPrompt.js +20 -0
  5. package/dist/commands/commit/context/systemPrompt.js +4 -1
  6. package/dist/commands/commit/context/userPrompt.js +4 -1
  7. package/dist/commands/commit/generateCommitMessage.js +16 -37
  8. package/dist/commands/commit/index.js +187 -178
  9. package/dist/commands/commit/summarizeDiff.js +193 -0
  10. package/dist/commands/config.js +24 -9
  11. package/dist/commands/hook/index.js +68 -0
  12. package/dist/commands/middleware/capabilitiesMiddleware/ghCapability.js +20 -20
  13. package/dist/commands/middleware/capabilitiesMiddleware/gitCapability.js +13 -10
  14. package/dist/commands/middleware/capabilitiesMiddleware/index.js +12 -11
  15. package/dist/commands/middleware/hasStagedChangesMiddleware.js +9 -6
  16. package/dist/commands/middleware/setupMiddleware/defaultModels.js +15 -0
  17. package/dist/commands/middleware/setupMiddleware/index.js +66 -38
  18. package/dist/commands/model.js +7 -4
  19. package/dist/commands/passthroughArgs.js +11 -0
  20. package/dist/commands/pr/context/systemPrompt.js +4 -1
  21. package/dist/commands/pr/context/userPrompt.js +4 -1
  22. package/dist/commands/pr/generatePRDetails.js +25 -31
  23. package/dist/commands/pr/getPRContext.js +37 -62
  24. package/dist/commands/pr/index.js +57 -62
  25. package/dist/commands/reset.js +26 -0
  26. package/dist/commands/review/index.js +31 -0
  27. package/dist/commands/setup.js +38 -13
  28. package/dist/config.js +63 -55
  29. package/dist/index.js +31 -62
  30. package/dist/llm/budget.js +10 -0
  31. package/dist/llm/index.js +12 -12
  32. package/dist/llm/providers/anthropic/index.js +31 -0
  33. package/dist/llm/providers/apiKey.js +41 -0
  34. package/dist/llm/providers/apple/client.js +77 -0
  35. package/dist/llm/providers/apple/index.js +69 -0
  36. package/dist/llm/providers/apple/models.js +29 -0
  37. package/dist/llm/providers/base.js +36 -0
  38. package/dist/llm/providers/local/index.js +84 -0
  39. package/dist/llm/providers/openai/index.js +19 -0
  40. package/dist/llm/providers/openaiCompatible.js +66 -0
  41. package/dist/llm/providers/openrouter/index.js +19 -0
  42. package/dist/llm/registry.js +39 -0
  43. package/dist/llm/setup/getAvailableModels.js +17 -0
  44. package/dist/llm/setup/selectModel.js +40 -0
  45. package/dist/llm/tokenCount.js +5 -0
  46. package/dist/package.js +67 -0
  47. package/dist/services/gh/createPullRequest.js +38 -58
  48. package/dist/services/gh/index.js +6 -3
  49. package/dist/services/gh/isAvailable.js +10 -8
  50. package/dist/services/git/executeGitAdd.js +11 -12
  51. package/dist/services/git/executeGitCommit.js +10 -11
  52. package/dist/services/git/getAmendChanges.js +23 -0
  53. package/dist/services/git/getChangedFiles.js +28 -61
  54. package/dist/services/git/getCommitsSinceBaseBranch.js +28 -56
  55. package/dist/services/git/getCurrentBranch.js +10 -8
  56. package/dist/services/git/getDefaultBranch.js +35 -60
  57. package/dist/services/git/getStagedChanges.js +10 -8
  58. package/dist/services/git/getStagedFiles.js +10 -9
  59. package/dist/services/git/hasStagedChanges.js +9 -8
  60. package/dist/services/git/index.js +17 -12
  61. package/dist/services/git/isAvailable.js +10 -8
  62. package/dist/services/git/isGitRepository.js +10 -8
  63. package/dist/utils/commitlint.js +97 -135
  64. package/dist/utils/formatBaseURL.js +7 -6
  65. package/dist/utils/maskApiKey.js +6 -7
  66. package/package.json +19 -5
  67. package/dist/commands/commit/context/systemPrompt.d.ts +0 -1
  68. package/dist/commands/commit/context/userPrompt.d.ts +0 -1
  69. package/dist/commands/commit/generateCommitMessage.d.ts +0 -1
  70. package/dist/commands/commit/index.d.ts +0 -7
  71. package/dist/commands/config.d.ts +0 -1
  72. package/dist/commands/middleware/capabilitiesMiddleware/ghCapability.d.ts +0 -1
  73. package/dist/commands/middleware/capabilitiesMiddleware/gitCapability.d.ts +0 -1
  74. package/dist/commands/middleware/capabilitiesMiddleware/index.d.ts +0 -3
  75. package/dist/commands/middleware/hasStagedChangesMiddleware.d.ts +0 -1
  76. package/dist/commands/middleware/setupMiddleware/getAvailableModels.d.ts +0 -4
  77. package/dist/commands/middleware/setupMiddleware/getAvailableModels.js +0 -11
  78. package/dist/commands/middleware/setupMiddleware/getOrUpdateApiKey.d.ts +0 -1
  79. package/dist/commands/middleware/setupMiddleware/getOrUpdateApiKey.js +0 -39
  80. package/dist/commands/middleware/setupMiddleware/index.d.ts +0 -4
  81. package/dist/commands/middleware/setupMiddleware/selectModel.d.ts +0 -5
  82. package/dist/commands/middleware/setupMiddleware/selectModel.js +0 -38
  83. package/dist/commands/middleware/setupMiddleware/setupLocalLLM.d.ts +0 -5
  84. package/dist/commands/middleware/setupMiddleware/setupLocalLLM.js +0 -60
  85. package/dist/commands/middleware/setupMiddleware/setupOpenRouter.d.ts +0 -2
  86. package/dist/commands/middleware/setupMiddleware/setupOpenRouter.js +0 -66
  87. package/dist/commands/middleware/setupMiddleware/types.d.ts +0 -13
  88. package/dist/commands/middleware/setupMiddleware/types.js +0 -1
  89. package/dist/commands/model.d.ts +0 -1
  90. package/dist/commands/pr/context/systemPrompt.d.ts +0 -1
  91. package/dist/commands/pr/context/userPrompt.d.ts +0 -1
  92. package/dist/commands/pr/generatePRDetails.d.ts +0 -4
  93. package/dist/commands/pr/getPRContext.d.ts +0 -1
  94. package/dist/commands/pr/index.d.ts +0 -10
  95. package/dist/commands/setup.d.ts +0 -3
  96. package/dist/config.d.ts +0 -18
  97. package/dist/index.d.ts +0 -2
  98. package/dist/llm/index.d.ts +0 -5
  99. package/dist/services/gh/createPullRequest.d.ts +0 -1
  100. package/dist/services/gh/index.d.ts +0 -4
  101. package/dist/services/gh/isAvailable.d.ts +0 -1
  102. package/dist/services/git/executeGitAdd.d.ts +0 -1
  103. package/dist/services/git/executeGitCommit.d.ts +0 -1
  104. package/dist/services/git/getChangedFiles.d.ts +0 -1
  105. package/dist/services/git/getCommitsSinceBaseBranch.d.ts +0 -1
  106. package/dist/services/git/getCurrentBranch.d.ts +0 -1
  107. package/dist/services/git/getDefaultBranch.d.ts +0 -1
  108. package/dist/services/git/getStagedChanges.d.ts +0 -1
  109. package/dist/services/git/getStagedFiles.d.ts +0 -1
  110. package/dist/services/git/hasStagedChanges.d.ts +0 -1
  111. package/dist/services/git/index.d.ts +0 -13
  112. package/dist/services/git/isAvailable.d.ts +0 -1
  113. package/dist/services/git/isGitRepository.d.ts +0 -1
  114. package/dist/utils/commitlint.d.ts +0 -25
  115. package/dist/utils/formatBaseURL.d.ts +0 -1
  116. package/dist/utils/maskApiKey.d.ts +0 -1
@@ -1,63 +1,43 @@
1
1
  import chalk from "chalk";
2
2
  import { execSync } from "child_process";
3
- export const createPullRequest = (title, body, baseBranch, draft) => {
4
- const draftFlag = draft ? "--draft" : "";
5
- try {
6
- console.log(chalk.blue(`Creating pull request to ${baseBranch}...`));
7
- // Create a temporary file for the PR body to avoid issues with escaping
8
- const tempFilePath = `/tmp/gitpt-pr-body-${Date.now()}.md`;
9
- try {
10
- // Write the body to a temporary file
11
- execSync(`cat > "${tempFilePath}" << 'GITPT_EOF'
3
+ //#region src/services/gh/createPullRequest.ts
4
+ var createPullRequest = (title, body, baseBranch, draft) => {
5
+ const draftFlag = draft ? "--draft" : "";
6
+ try {
7
+ console.log(chalk.blue(`Creating pull request to ${baseBranch}...`));
8
+ const tempFilePath = `/tmp/gitpt-pr-body-${Date.now()}.md`;
9
+ try {
10
+ execSync(`cat > "${tempFilePath}" << 'GITPT_EOF'
12
11
  ${body}
13
12
  GITPT_EOF`);
14
- // Try to get the remote repo URL if available
15
- let repoUrlArg = "";
16
- try {
17
- const repoUrl = execSync("git config --get remote.origin.url")
18
- .toString()
19
- .trim();
20
- if (repoUrl) {
21
- repoUrlArg = `--repo "${repoUrl}"`;
22
- }
23
- }
24
- catch (e) {
25
- // Proceed without repo URL
26
- }
27
- // Use the file for the body
28
- const command = `gh pr create --title "${title.replace(/"/g, '\\"')}" --body-file "${tempFilePath}" --base "${baseBranch}" ${draftFlag} ${repoUrlArg}`;
29
- // Set a timeout to avoid hanging indefinitely
30
- console.log(chalk.gray("Running GitHub PR creation command..."));
31
- console.log(chalk.gray(`Using base branch: ${baseBranch}`));
32
- // Add debugging output
33
- console.log(chalk.gray("Executing command with 60s timeout:"));
34
- // Execute the command with a timeout
35
- const result = execSync(command, {
36
- stdio: "pipe",
37
- timeout: 60000, // 60-second timeout
38
- }).toString();
39
- console.log(result);
40
- console.log(chalk.green(" Pull request created successfully"));
41
- }
42
- finally {
43
- // Clean up temporary file
44
- try {
45
- execSync(`rm -f "${tempFilePath}"`);
46
- }
47
- catch (e) {
48
- // Ignore cleanup errors
49
- }
50
- }
51
- }
52
- catch (error) {
53
- if (error instanceof Error && error.message.includes("timeout")) {
54
- console.error(chalk.red("Error: GitHub CLI command timed out after 60 seconds."));
55
- console.log(chalk.yellow("You may need to create the PR manually using:"));
56
- console.log(chalk.yellow(`gh pr create --title "${title}" --base "${baseBranch}" ${draftFlag}`));
57
- }
58
- else {
59
- console.error(chalk.red("Error creating pull request:"), error);
60
- }
61
- throw new Error("Failed to create pull request");
62
- }
13
+ let repoUrlArg = "";
14
+ try {
15
+ const repoUrl = execSync("git config --get remote.origin.url").toString().trim();
16
+ if (repoUrl) repoUrlArg = `--repo "${repoUrl}"`;
17
+ } catch (e) {}
18
+ const command = `gh pr create --title "${title.replace(/"/g, "\\\"")}" --body-file "${tempFilePath}" --base "${baseBranch}" ${draftFlag} ${repoUrlArg}`;
19
+ console.log(chalk.gray("Running GitHub PR creation command..."));
20
+ console.log(chalk.gray(`Using base branch: ${baseBranch}`));
21
+ console.log(chalk.gray("Executing command with 60s timeout:"));
22
+ const result = execSync(command, {
23
+ stdio: "pipe",
24
+ timeout: 6e4
25
+ }).toString();
26
+ console.log(result);
27
+ console.log(chalk.green(" Pull request created successfully"));
28
+ } finally {
29
+ try {
30
+ execSync(`rm -f "${tempFilePath}"`);
31
+ } catch (e) {}
32
+ }
33
+ } catch (error) {
34
+ if (error instanceof Error && error.message.includes("timeout")) {
35
+ console.error(chalk.red("Error: GitHub CLI command timed out after 60 seconds."));
36
+ console.log(chalk.yellow("You may need to create the PR manually using:"));
37
+ console.log(chalk.yellow(`gh pr create --title "${title}" --base "${baseBranch}" ${draftFlag}`));
38
+ } else console.error(chalk.red("Error creating pull request:"), error);
39
+ throw new Error("Failed to create pull request");
40
+ }
63
41
  };
42
+ //#endregion
43
+ export { createPullRequest };
@@ -1,6 +1,9 @@
1
1
  import { createPullRequest } from "./createPullRequest.js";
2
2
  import { isAvailable } from "./isAvailable.js";
3
- export const gh = {
4
- createPullRequest,
5
- isAvailable,
3
+ //#region src/services/gh/index.ts
4
+ var gh = {
5
+ createPullRequest,
6
+ isAvailable
6
7
  };
8
+ //#endregion
9
+ export { gh };
@@ -1,10 +1,12 @@
1
1
  import { execSync } from "child_process";
2
- export const isAvailable = () => {
3
- try {
4
- execSync("gh --version", { stdio: "ignore" });
5
- return true;
6
- }
7
- catch (error) {
8
- return false;
9
- }
2
+ //#region src/services/gh/isAvailable.ts
3
+ var isAvailable = () => {
4
+ try {
5
+ execSync("gh --version", { stdio: "ignore" });
6
+ return true;
7
+ } catch (error) {
8
+ return false;
9
+ }
10
10
  };
11
+ //#endregion
12
+ export { isAvailable };
@@ -1,15 +1,14 @@
1
1
  import chalk from "chalk";
2
2
  import { execSync } from "child_process";
3
- export const executeGitAdd = (files) => {
4
- try {
5
- if (files.length === 0) {
6
- throw new Error("No files specified");
7
- }
8
- const fileArgs = files.join(" ");
9
- execSync(`git add ${fileArgs}`, { stdio: "inherit" });
10
- }
11
- catch (error) {
12
- console.error(chalk.red("Error adding files:"), error);
13
- throw new Error("Failed to add files to git");
14
- }
3
+ //#region src/services/git/executeGitAdd.ts
4
+ var executeGitAdd = (files) => {
5
+ try {
6
+ if (files.length === 0) throw new Error("No files specified");
7
+ execSync(`git add ${files.join(" ")}`, { stdio: "inherit" });
8
+ } catch (error) {
9
+ console.error(chalk.red("Error adding files:"), error);
10
+ throw new Error("Failed to add files to git");
11
+ }
15
12
  };
13
+ //#endregion
14
+ export { executeGitAdd };
@@ -1,12 +1,11 @@
1
- import chalk from "chalk";
2
- import { execSync } from "child_process";
3
- export const executeGitCommit = (message, additionalArgs = []) => {
4
- try {
5
- const args = additionalArgs.join(" ");
6
- execSync(`git commit -m "${message}" ${args}`, { stdio: "inherit" });
7
- }
8
- catch (error) {
9
- console.error(chalk.red("Error committing changes:"), error);
10
- throw new Error("Failed to commit changes");
11
- }
1
+ import { spawnSync } from "child_process";
2
+ //#region src/services/git/executeGitCommit.ts
3
+ var executeGitCommit = (message, additionalArgs = []) => {
4
+ if (spawnSync("git", [
5
+ "commit",
6
+ ...message === null ? [] : ["-m", message],
7
+ ...additionalArgs
8
+ ], { stdio: "inherit" }).status !== 0) throw new Error("Failed to commit changes");
12
9
  };
10
+ //#endregion
11
+ export { executeGitCommit };
@@ -0,0 +1,23 @@
1
+ import chalk from "chalk";
2
+ import { execSync } from "child_process";
3
+ //#region src/services/git/getAmendChanges.ts
4
+ /**
5
+ * The content of the commit being amended: the staged tree compared to the
6
+ * commit before HEAD — so a plain reword still has a diff (even with nothing
7
+ * staged), and any new staged changes are folded in. Falls back to the staged
8
+ * diff when there is no previous commit (amending the very first commit).
9
+ */
10
+ var getAmendChanges = () => {
11
+ try {
12
+ return execSync("git diff --staged --function-context HEAD~1").toString();
13
+ } catch {
14
+ try {
15
+ return execSync("git diff --staged --function-context").toString();
16
+ } catch (error) {
17
+ console.error(chalk.red("Error getting amend changes:"), error);
18
+ throw new Error("Failed to get amend changes");
19
+ }
20
+ }
21
+ };
22
+ //#endregion
23
+ export { getAmendChanges };
@@ -1,64 +1,31 @@
1
1
  import chalk from "chalk";
2
2
  import { execSync } from "child_process";
3
- export const getChangedFiles = (baseBranch) => {
4
- // Try several methods to get changed files
5
- // Method 1: Compare with origin/baseBranch using three dots
6
- try {
7
- const changedFiles = execSync(`git diff --name-only origin/${baseBranch}...HEAD`)
8
- .toString()
9
- .trim();
10
- if (changedFiles) {
11
- return changedFiles.split("\n").filter(Boolean);
12
- }
13
- }
14
- catch (error) {
15
- // Continue to next method
16
- }
17
- // Method 2: Compare with local baseBranch using three dots
18
- try {
19
- const changedFiles = execSync(`git diff --name-only ${baseBranch}...HEAD`)
20
- .toString()
21
- .trim();
22
- if (changedFiles) {
23
- return changedFiles.split("\n").filter(Boolean);
24
- }
25
- }
26
- catch (error) {
27
- // Continue to next method
28
- }
29
- // Method 3: Direct comparison with two dots
30
- try {
31
- const changedFiles = execSync(`git diff --name-only ${baseBranch}..HEAD`)
32
- .toString()
33
- .trim();
34
- if (changedFiles) {
35
- return changedFiles.split("\n").filter(Boolean);
36
- }
37
- }
38
- catch (error) {
39
- // Continue to next method
40
- }
41
- // Method 4: Get recently modified files
42
- try {
43
- console.log(chalk.yellow(`Could not determine changed files relative to ${baseBranch}, using recently modified files...`));
44
- const changedFiles = execSync("git ls-files --modified --others --exclude-standard")
45
- .toString()
46
- .trim();
47
- if (changedFiles) {
48
- return changedFiles.split("\n").filter(Boolean);
49
- }
50
- }
51
- catch (error) {
52
- // Last resort
53
- }
54
- // Method 5: List all files in the repo as a last resort
55
- try {
56
- console.log(chalk.yellow("Using all tracked files as fallback..."));
57
- const allFiles = execSync("git ls-files").toString().trim();
58
- return allFiles.split("\n").filter(Boolean).slice(0, 50); // Limit to first 50 files
59
- }
60
- catch (error) {
61
- console.error(chalk.red("Could not determine changed files."));
62
- return [];
63
- }
3
+ //#region src/services/git/getChangedFiles.ts
4
+ var getChangedFiles = (baseBranch) => {
5
+ try {
6
+ const changedFiles = execSync(`git diff --name-only origin/${baseBranch}...HEAD`).toString().trim();
7
+ if (changedFiles) return changedFiles.split("\n").filter(Boolean);
8
+ } catch (error) {}
9
+ try {
10
+ const changedFiles = execSync(`git diff --name-only ${baseBranch}...HEAD`).toString().trim();
11
+ if (changedFiles) return changedFiles.split("\n").filter(Boolean);
12
+ } catch (error) {}
13
+ try {
14
+ const changedFiles = execSync(`git diff --name-only ${baseBranch}..HEAD`).toString().trim();
15
+ if (changedFiles) return changedFiles.split("\n").filter(Boolean);
16
+ } catch (error) {}
17
+ try {
18
+ console.log(chalk.yellow(`Could not determine changed files relative to ${baseBranch}, using recently modified files...`));
19
+ const changedFiles = execSync("git ls-files --modified --others --exclude-standard").toString().trim();
20
+ if (changedFiles) return changedFiles.split("\n").filter(Boolean);
21
+ } catch (error) {}
22
+ try {
23
+ console.log(chalk.yellow("Using all tracked files as fallback..."));
24
+ return execSync("git ls-files").toString().trim().split("\n").filter(Boolean).slice(0, 50);
25
+ } catch (error) {
26
+ console.error(chalk.red("Could not determine changed files."));
27
+ return [];
28
+ }
64
29
  };
30
+ //#endregion
31
+ export { getChangedFiles };
@@ -1,59 +1,31 @@
1
1
  import chalk from "chalk";
2
2
  import { execSync } from "child_process";
3
- export const getCommitsSinceBaseBranch = (baseBranch) => {
4
- try {
5
- // Try first with origin/baseBranch
6
- try {
7
- const mergeBase = execSync(`git merge-base HEAD origin/${baseBranch}`)
8
- .toString()
9
- .trim();
10
- const commitMessages = execSync(`git log --pretty=format:"%s" ${mergeBase}..HEAD`)
11
- .toString()
12
- .trim();
13
- if (commitMessages) {
14
- return commitMessages.split("\n").filter(Boolean);
15
- }
16
- }
17
- catch (error) {
18
- // If origin/baseBranch doesn't exist, try with just baseBranch
19
- console.log(chalk.yellow(`No origin/${baseBranch} found, trying with local ${baseBranch} branch...`));
20
- }
21
- // Try with local branch
22
- try {
23
- const mergeBase = execSync(`git merge-base HEAD ${baseBranch}`)
24
- .toString()
25
- .trim();
26
- const commitMessages = execSync(`git log --pretty=format:"%s" ${mergeBase}..HEAD`)
27
- .toString()
28
- .trim();
29
- if (commitMessages) {
30
- return commitMessages.split("\n").filter(Boolean);
31
- }
32
- }
33
- catch (error) {
34
- // If that fails too, fallback to simple branch comparison
35
- console.log(chalk.yellow(`Merge base with ${baseBranch} not found, comparing branches directly...`));
36
- }
37
- // Direct branch comparison
38
- try {
39
- const commitMessages = execSync(`git log --pretty=format:"%s" ${baseBranch}..HEAD`)
40
- .toString()
41
- .trim();
42
- if (commitMessages) {
43
- return commitMessages.split("\n").filter(Boolean);
44
- }
45
- }
46
- catch (error) {
47
- console.log(chalk.yellow(`Could not compare with ${baseBranch}, using recent commits...`));
48
- }
49
- // Last resort: get most recent commits
50
- const commitMessages = execSync('git log --pretty=format:"%s" -n 10')
51
- .toString()
52
- .trim();
53
- return commitMessages.split("\n").filter(Boolean);
54
- }
55
- catch (error) {
56
- console.error(chalk.yellow("Could not get commits. Using empty list."));
57
- return [];
58
- }
3
+ //#region src/services/git/getCommitsSinceBaseBranch.ts
4
+ var getCommitsSinceBaseBranch = (baseBranch) => {
5
+ try {
6
+ try {
7
+ const commitMessages = execSync(`git log --pretty=format:"%s" ${execSync(`git merge-base HEAD origin/${baseBranch}`).toString().trim()}..HEAD`).toString().trim();
8
+ if (commitMessages) return commitMessages.split("\n").filter(Boolean);
9
+ } catch (error) {
10
+ console.log(chalk.yellow(`No origin/${baseBranch} found, trying with local ${baseBranch} branch...`));
11
+ }
12
+ try {
13
+ const commitMessages = execSync(`git log --pretty=format:"%s" ${execSync(`git merge-base HEAD ${baseBranch}`).toString().trim()}..HEAD`).toString().trim();
14
+ if (commitMessages) return commitMessages.split("\n").filter(Boolean);
15
+ } catch (error) {
16
+ console.log(chalk.yellow(`Merge base with ${baseBranch} not found, comparing branches directly...`));
17
+ }
18
+ try {
19
+ const commitMessages = execSync(`git log --pretty=format:"%s" ${baseBranch}..HEAD`).toString().trim();
20
+ if (commitMessages) return commitMessages.split("\n").filter(Boolean);
21
+ } catch (error) {
22
+ console.log(chalk.yellow(`Could not compare with ${baseBranch}, using recent commits...`));
23
+ }
24
+ return execSync("git log --pretty=format:\"%s\" -n 10").toString().trim().split("\n").filter(Boolean);
25
+ } catch (error) {
26
+ console.error(chalk.yellow("Could not get commits. Using empty list."));
27
+ return [];
28
+ }
59
29
  };
30
+ //#endregion
31
+ export { getCommitsSinceBaseBranch };
@@ -1,11 +1,13 @@
1
1
  import chalk from "chalk";
2
2
  import { execSync } from "child_process";
3
- export const getCurrentBranch = () => {
4
- try {
5
- return execSync("git rev-parse --abbrev-ref HEAD").toString().trim();
6
- }
7
- catch (error) {
8
- console.error(chalk.red("Error getting current branch:"), error);
9
- throw new Error("Failed to get current branch");
10
- }
3
+ //#region src/services/git/getCurrentBranch.ts
4
+ var getCurrentBranch = () => {
5
+ try {
6
+ return execSync("git rev-parse --abbrev-ref HEAD").toString().trim();
7
+ } catch (error) {
8
+ console.error(chalk.red("Error getting current branch:"), error);
9
+ throw new Error("Failed to get current branch");
10
+ }
11
11
  };
12
+ //#endregion
13
+ export { getCurrentBranch };
@@ -1,63 +1,38 @@
1
1
  import chalk from "chalk";
2
2
  import { execSync } from "child_process";
3
- export const getDefaultBranch = () => {
4
- try {
5
- // First check for a default branch set in git config
6
- try {
7
- const defaultBranch = execSync("git config init.defaultBranch")
8
- .toString()
9
- .trim();
10
- if (defaultBranch) {
11
- return defaultBranch;
12
- }
13
- }
14
- catch (error) {
15
- // Continue if git config doesn't have default branch
16
- }
17
- // Next, check if GitHub CLI can tell us the default branch
18
- try {
19
- const repoInfo = execSync("gh repo view --json defaultBranchRef --jq .defaultBranchRef.name")
20
- .toString()
21
- .trim();
22
- if (repoInfo) {
23
- return repoInfo;
24
- }
25
- }
26
- catch (error) {
27
- // Continue if gh command fails
28
- }
29
- // Try to find default branch in remote branches list
30
- const branches = execSync("git branch -r").toString().trim().split("\n");
31
- // Common default branch names, in order of likelihood
32
- const mainPatterns = [
33
- /origin\/main$/,
34
- /origin\/master$/,
35
- /origin\/develop$/,
36
- /origin\/dev$/,
37
- /origin\/trunk$/,
38
- ];
39
- // Try each pattern in order
40
- for (const pattern of mainPatterns) {
41
- const defaultBranch = branches.find((b) => pattern.test(b.trim()));
42
- if (defaultBranch) {
43
- return defaultBranch.trim().replace(/^origin\//, "");
44
- }
45
- }
46
- // Check for a branch that has 'HEAD -> origin/' in it, indicating the default branch
47
- const headBranch = branches.find((b) => b.includes("HEAD -> origin/"));
48
- if (headBranch) {
49
- const match = headBranch.match(/HEAD -> origin\/([^,\s]+)/);
50
- if (match && match[1]) {
51
- return match[1];
52
- }
53
- }
54
- // Fallback to 'main' as most GitHub repos use this now
55
- console.log(chalk.yellow('Could not determine default branch, using "main"'));
56
- return "main";
57
- }
58
- catch (error) {
59
- // If we can't determine, default to main
60
- console.log(chalk.yellow('Error detecting default branch, using "main"'));
61
- return "main";
62
- }
3
+ //#region src/services/git/getDefaultBranch.ts
4
+ var getDefaultBranch = () => {
5
+ try {
6
+ try {
7
+ const defaultBranch = execSync("git config init.defaultBranch").toString().trim();
8
+ if (defaultBranch) return defaultBranch;
9
+ } catch (error) {}
10
+ try {
11
+ const repoInfo = execSync("gh repo view --json defaultBranchRef --jq .defaultBranchRef.name").toString().trim();
12
+ if (repoInfo) return repoInfo;
13
+ } catch (error) {}
14
+ const branches = execSync("git branch -r").toString().trim().split("\n");
15
+ for (const pattern of [
16
+ /origin\/main$/,
17
+ /origin\/master$/,
18
+ /origin\/develop$/,
19
+ /origin\/dev$/,
20
+ /origin\/trunk$/
21
+ ]) {
22
+ const defaultBranch = branches.find((b) => pattern.test(b.trim()));
23
+ if (defaultBranch) return defaultBranch.trim().replace(/^origin\//, "");
24
+ }
25
+ const headBranch = branches.find((b) => b.includes("HEAD -> origin/"));
26
+ if (headBranch) {
27
+ const match = headBranch.match(/HEAD -> origin\/([^,\s]+)/);
28
+ if (match && match[1]) return match[1];
29
+ }
30
+ console.log(chalk.yellow("Could not determine default branch, using \"main\""));
31
+ return "main";
32
+ } catch (error) {
33
+ console.log(chalk.yellow("Error detecting default branch, using \"main\""));
34
+ return "main";
35
+ }
63
36
  };
37
+ //#endregion
38
+ export { getDefaultBranch };
@@ -1,11 +1,13 @@
1
1
  import chalk from "chalk";
2
2
  import { execSync } from "child_process";
3
- export const getStagedChanges = () => {
4
- try {
5
- return execSync("git diff --staged").toString();
6
- }
7
- catch (error) {
8
- console.error(chalk.red("Error getting staged changes:"), error);
9
- throw new Error("Failed to get staged changes");
10
- }
3
+ //#region src/services/git/getStagedChanges.ts
4
+ var getStagedChanges = () => {
5
+ try {
6
+ return execSync("git diff --staged --function-context").toString();
7
+ } catch (error) {
8
+ console.error(chalk.red("Error getting staged changes:"), error);
9
+ throw new Error("Failed to get staged changes");
10
+ }
11
11
  };
12
+ //#endregion
13
+ export { getStagedChanges };
@@ -1,12 +1,13 @@
1
1
  import chalk from "chalk";
2
2
  import { execSync } from "child_process";
3
- export const getStagedFiles = () => {
4
- try {
5
- const result = execSync("git diff --staged --name-only").toString();
6
- return result.split("\n").filter(Boolean);
7
- }
8
- catch (error) {
9
- console.error(chalk.red("Error getting staged files:"), error);
10
- throw new Error("Failed to get staged files");
11
- }
3
+ //#region src/services/git/getStagedFiles.ts
4
+ var getStagedFiles = () => {
5
+ try {
6
+ return execSync("git diff --staged --name-only").toString().split("\n").filter(Boolean);
7
+ } catch (error) {
8
+ console.error(chalk.red("Error getting staged files:"), error);
9
+ throw new Error("Failed to get staged files");
10
+ }
12
11
  };
12
+ //#endregion
13
+ export { getStagedFiles };
@@ -1,10 +1,11 @@
1
1
  import { execSync } from "child_process";
2
- export const hasStagedChanges = () => {
3
- try {
4
- const output = execSync('git diff --staged --quiet || echo "has-changes"').toString();
5
- return output.includes("has-changes");
6
- }
7
- catch (error) {
8
- return true; // Assume there are changes if we can't check
9
- }
2
+ //#region src/services/git/hasStagedChanges.ts
3
+ var hasStagedChanges = () => {
4
+ try {
5
+ return execSync("git diff --staged --quiet || echo \"has-changes\"").toString().includes("has-changes");
6
+ } catch (error) {
7
+ return true;
8
+ }
10
9
  };
10
+ //#endregion
11
+ export { hasStagedChanges };
@@ -1,6 +1,7 @@
1
1
  import { executeGitAdd } from "./executeGitAdd.js";
2
2
  import { executeGitCommit } from "./executeGitCommit.js";
3
3
  import { getChangedFiles } from "./getChangedFiles.js";
4
+ import { getAmendChanges } from "./getAmendChanges.js";
4
5
  import { getCommitsSinceBaseBranch } from "./getCommitsSinceBaseBranch.js";
5
6
  import { getCurrentBranch } from "./getCurrentBranch.js";
6
7
  import { getDefaultBranch } from "./getDefaultBranch.js";
@@ -9,16 +10,20 @@ import { getStagedFiles } from "./getStagedFiles.js";
9
10
  import { hasStagedChanges } from "./hasStagedChanges.js";
10
11
  import { isAvailable } from "./isAvailable.js";
11
12
  import { isGitRepository } from "./isGitRepository.js";
12
- export const git = {
13
- add: executeGitAdd,
14
- commit: executeGitCommit,
15
- getChangedFiles,
16
- getCommitsSinceBaseBranch,
17
- getCurrentBranch,
18
- getDefaultBranch,
19
- hasStagedChanges,
20
- getStagedChanges,
21
- getStagedFiles,
22
- isAvailable,
23
- isGitRepository,
13
+ //#region src/services/git/index.ts
14
+ var git = {
15
+ add: executeGitAdd,
16
+ commit: executeGitCommit,
17
+ getAmendChanges,
18
+ getChangedFiles,
19
+ getCommitsSinceBaseBranch,
20
+ getCurrentBranch,
21
+ getDefaultBranch,
22
+ hasStagedChanges,
23
+ getStagedChanges,
24
+ getStagedFiles,
25
+ isAvailable,
26
+ isGitRepository
24
27
  };
28
+ //#endregion
29
+ export { git };