Skip to content

Commit 81fbdf3

Browse files
committed
Add {branch} option to gitRevision
Resolves #3041
1 parent fd3344f commit 81fbdf3

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ title: Changelog
66

77
### Features
88

9+
- The `gitRevision` option now accepts the special value `{branch}`, which indicates source links should use
10+
the current git branch for links, #3041.
911
- Introduced `validation.invalidPath` for suppressing warnings caused by referencing relative paths which
1012
do not exist when building the documentation, #3033.
1113
- API: Introduced `Logger.validationWarning` for validation which occurs during conversion rather than

site/options/input.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,13 @@ placeholders.
297297
## gitRevision
298298

299299
```bash
300-
typedoc --gitRevision <revision|branch>
300+
typedoc --gitRevision <revision|branch|"{branch}">
301301
```
302302

303-
Has no effect if `--disableSources` is set.
304-
Use specified revision or branch instead of the last revision for linking to source files. Defaults to the last commit.
303+
Has no effect if `--disableSources` is set. Use specified revision or branch instead of the last revision for linking to
304+
source files. Defaults to the last commit. Accepts the special value `{branch}` to indicate that `{gitRevision}` in
305+
`sourceLinkTemplate` should be set to the current commit branch. If `gitRevision` is set to `{branch}` and the current
306+
HEAD is not set to the tip of a branch, TypeDoc will use the last commit instead.
305307

306308
## gitRemote
307309

src/lib/converter/utils/repository.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ export class GitRepository implements Repository {
125125
gitRemote: string,
126126
logger: Logger,
127127
): GitRepository | undefined {
128+
if (gitRevision === "{branch}") {
129+
gitRevision = git("-C", path, "branch", "--show-current").stdout.trim();
130+
}
128131
gitRevision ||= git("-C", path, "rev-parse", "HEAD").stdout.trim();
129132
if (gitRevision == "HEAD") return; // Will only happen in a repo with no commits.
130133

src/test/Repository.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,16 @@ describe("Repository", function () {
155155
repo.getURL(normalizePath(join(project.cwd, "test.js")), 1),
156156
"b53cc55bcdd9bc5920787a1d4a4a15fa24123b04/b53cc55b/test.js/1",
157157
);
158+
159+
const repo2 = GitRepository.tryCreateRepository(
160+
project.cwd,
161+
"{gitRevision}/{gitRevision:short}/{path}/{line}",
162+
"{branch}", // revision
163+
"origin", // remote
164+
new TestLogger(),
165+
);
166+
167+
equal(repo2?.gitRevision, "test");
158168
});
159169
});
160170
});

0 commit comments

Comments
 (0)