git-coco 0.41.1 → 0.41.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.
@@ -53,7 +53,7 @@ import { pathToFileURL } from 'url';
53
53
  /**
54
54
  * Current build version from package.json
55
55
  */
56
- const BUILD_VERSION = "0.41.1";
56
+ const BUILD_VERSION = "0.41.2";
57
57
 
58
58
  const isInteractive = (config) => {
59
59
  return config?.mode === 'interactive' || !!config?.interactive;
@@ -6750,13 +6750,35 @@ async function getCommitLogRangeDetails(from, to, { noMerges, git }) {
6750
6750
  }
6751
6751
 
6752
6752
  /**
6753
- * Retrieves the name of the current branch.
6753
+ * Retrieve the name of the current branch.
6754
6754
  *
6755
- * @param {GetCurrentBranchName} options - The options for retrieving the branch name.
6756
- * @returns {Promise<string>} - A promise that resolves to the name of the current branch.
6755
+ * The first-choice path uses `git rev-parse --abbrev-ref HEAD`, which
6756
+ * returns the active branch on a normal repo. On an initial-commit
6757
+ * repo (fresh `git init` with no commits yet) HEAD does not resolve
6758
+ * and rev-parse fails fatally — but `git symbolic-ref --short HEAD`
6759
+ * still reports the configured initial branch name, so we fall
6760
+ * through to that. Final fallback is an empty string for genuinely
6761
+ * detached / corrupt states; every caller treats that as "no branch
6762
+ * context", which is the right semantics for a no-HEAD repo.
6763
+ *
6764
+ * Without this resilience, every command that depends on the branch
6765
+ * name (e.g. the post-summary step in `coco commit`) would crash
6766
+ * with `fatal: ambiguous argument 'HEAD'` after the entire diff
6767
+ * pipeline already ran (#844).
6757
6768
  */
6758
6769
  async function getCurrentBranchName({ git }) {
6759
- return await git.revparse(['--abbrev-ref', 'HEAD']);
6770
+ try {
6771
+ return await git.revparse(['--abbrev-ref', 'HEAD']);
6772
+ }
6773
+ catch {
6774
+ try {
6775
+ const ref = await git.raw(['symbolic-ref', '--short', 'HEAD']);
6776
+ return ref.trim();
6777
+ }
6778
+ catch {
6779
+ return '';
6780
+ }
6781
+ }
6760
6782
  }
6761
6783
 
6762
6784
  /**
package/dist/index.js CHANGED
@@ -78,7 +78,7 @@ var readline__namespace = /*#__PURE__*/_interopNamespaceDefault(readline);
78
78
  /**
79
79
  * Current build version from package.json
80
80
  */
81
- const BUILD_VERSION = "0.41.1";
81
+ const BUILD_VERSION = "0.41.2";
82
82
 
83
83
  const isInteractive = (config) => {
84
84
  return config?.mode === 'interactive' || !!config?.interactive;
@@ -6775,13 +6775,35 @@ async function getCommitLogRangeDetails(from, to, { noMerges, git }) {
6775
6775
  }
6776
6776
 
6777
6777
  /**
6778
- * Retrieves the name of the current branch.
6778
+ * Retrieve the name of the current branch.
6779
6779
  *
6780
- * @param {GetCurrentBranchName} options - The options for retrieving the branch name.
6781
- * @returns {Promise<string>} - A promise that resolves to the name of the current branch.
6780
+ * The first-choice path uses `git rev-parse --abbrev-ref HEAD`, which
6781
+ * returns the active branch on a normal repo. On an initial-commit
6782
+ * repo (fresh `git init` with no commits yet) HEAD does not resolve
6783
+ * and rev-parse fails fatally — but `git symbolic-ref --short HEAD`
6784
+ * still reports the configured initial branch name, so we fall
6785
+ * through to that. Final fallback is an empty string for genuinely
6786
+ * detached / corrupt states; every caller treats that as "no branch
6787
+ * context", which is the right semantics for a no-HEAD repo.
6788
+ *
6789
+ * Without this resilience, every command that depends on the branch
6790
+ * name (e.g. the post-summary step in `coco commit`) would crash
6791
+ * with `fatal: ambiguous argument 'HEAD'` after the entire diff
6792
+ * pipeline already ran (#844).
6782
6793
  */
6783
6794
  async function getCurrentBranchName({ git }) {
6784
- return await git.revparse(['--abbrev-ref', 'HEAD']);
6795
+ try {
6796
+ return await git.revparse(['--abbrev-ref', 'HEAD']);
6797
+ }
6798
+ catch {
6799
+ try {
6800
+ const ref = await git.raw(['symbolic-ref', '--short', 'HEAD']);
6801
+ return ref.trim();
6802
+ }
6803
+ catch {
6804
+ return '';
6805
+ }
6806
+ }
6785
6807
  }
6786
6808
 
6787
6809
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "git-coco",
3
- "version": "0.41.1",
3
+ "version": "0.41.2",
4
4
  "description": "zero-effort git commits with coco.",
5
5
  "author": "gfargo <ghfargo@gmail.com>",
6
6
  "license": "MIT",