File tree Expand file tree Collapse file tree 2 files changed +36
-7
lines changed Expand file tree Collapse file tree 2 files changed +36
-7
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * A Babel plugin macro giving access to git information at compile time.
3+ */
14declare module "react-git-info/macro" {
5+ /**
6+ * Information about a git commit.
7+ */
28 export interface GitCommitInformation {
9+ /**
10+ * Date of the commit as a string in strict ISO 8601 format.
11+ */
312 readonly date : string ;
13+ /**
14+ * Full hash of the latest commit on the active branch.
15+ */
416 readonly hash : string ;
17+ /**
18+ * Raw commit message.
19+ */
520 readonly message : string ;
21+ /**
22+ * Abbreviated commit hash with length defined as `core.abbrev` in
23+ * {@link https://git-scm.com/docs/git-config | git-config}.
24+ */
625 readonly shortHash : string ;
726 }
827
928 export interface GitInformation {
29+ /**
30+ * Tags pointing to the current commit.
31+ */
1032 readonly tags : string [ ] ;
11- readonly branch : string ;
33+ /**
34+ * The current git branch. `undefined` if the repository is in a detached HEAD state.
35+ */
36+ readonly branch ?: string ;
37+ /**
38+ * Information about the commit pointed to by `HEAD`.
39+ */
1240 readonly commit : GitCommitInformation ;
1341 }
1442
43+ /**
44+ * Returns information about the current Git state.
45+ */
1546 export default function GitInfo ( ) : GitInformation ;
1647}
Original file line number Diff line number Diff line change @@ -20,8 +20,10 @@ const parseRefs = (refs) => {
2020 let branch = undefined ;
2121 const tags = [ ] ;
2222 refs . split ( ', ' ) . map ( ( item ) => {
23- const isBranch = item . match ( / H E A D - > ( .* ) / ) ;
24- const isTag = item . match ( / t a g : ( .* ) / ) ;
23+ // if HEAD is not detached, the branch is printed out as `HEAD -> branch_name`.
24+ // if HEAD is detached, the output becomes `HEAD`.
25+ const isBranch = item . match ( / ^ H E A D - > ( .* ) $ / ) ;
26+ const isTag = item . match ( / ^ t a g : ( .* ) $ / ) ;
2527
2628 if ( isTag && isTag . length > 1 ) {
2729 tags . push ( isTag [ 1 ] ) ;
@@ -30,10 +32,6 @@ const parseRefs = (refs) => {
3032 }
3133 } ) ;
3234
33- if ( ! branch ) {
34- throw Error ( 'Unable to get parse branch from the log result.' ) ;
35- }
36-
3735 return [ branch , tags ] ;
3836} ;
3937
You can’t perform that action at this time.
0 commit comments