Skip to content

Commit 44cfaee

Browse files
committed
compare-screenshots: allow @{u} shorthand for upstream
Treat @{u} as equivalent to @@{u} since refs cannot start with a curly brace. This allows conveniently comparing the upstream branch against the current worktree. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent ebebddb commit 44cfaee

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

script/compare-screenshots.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ path is given, Hugo is run to build the site and a local server is started.
1111
Use worktree@commit to checkout a specific commit before building.
1212
Use worktree:/path/to/page to navigate to a specific page.
1313
Both can be combined: worktree@commit:/path/to/page
14+
As a convenience, @commit implies the current directory, and @{u} is
15+
treated as @@{u} since refs cannot start with a curly brace.
1416
1517
Options:
1618
--dark Emulate dark mode (prefers-color-scheme: dark)
@@ -21,6 +23,7 @@ Examples:
2123
node script/compare-screenshots.js https://git-scm.com http://localhost:5000
2224
node script/compare-screenshots.js https://git-scm.com /path/to/worktree
2325
node script/compare-screenshots.js https://git-scm.com @HEAD~2
26+
node script/compare-screenshots.js @{u} .
2427
node script/compare-screenshots.js https://git-scm.com/docs/git-config /path/to/worktree:/docs/git-config
2528
node script/compare-screenshots.js --dark https://git-scm.com http://localhost:5000
2629
node script/compare-screenshots.js --clip=1280x720+0+0 https://git-scm.com http://localhost:5000`;
@@ -39,6 +42,7 @@ const path = require('path');
3942
* . -> { worktreePath: '.', commit: undefined, pagePath: '' }
4043
* @HEAD~2 -> { worktreePath: '.', commit: 'HEAD~2', pagePath: '' }
4144
* .@HEAD~2 -> { worktreePath: '.', commit: 'HEAD~2', pagePath: '' }
45+
* @{u} -> { worktreePath: '.', commit: '@{u}', pagePath: '' }
4246
* /path/to/worktree:/docs/git -> { worktreePath: '/path/to/worktree', commit: undefined, pagePath: 'docs/git' }
4347
* .@main:/about -> { worktreePath: '.', commit: 'main', pagePath: 'about' }
4448
*
@@ -53,7 +57,9 @@ function getWorktreeInfo(arg) {
5357
const pagePath = colonIndex === -1 ? '' : arg.slice(colonIndex + 1).replace(/^\/+/, '');
5458
const atIndex = beforeColon.indexOf('@');
5559
const worktreePath = atIndex === -1 ? beforeColon : beforeColon.slice(0, atIndex);
56-
const commit = atIndex === -1 ? undefined : beforeColon.slice(atIndex + 1);
60+
let commit = atIndex === -1 ? undefined : beforeColon.slice(atIndex + 1);
61+
// Allow @{u} as shorthand for @@{u} since refs can't start with {
62+
if (commit && commit.startsWith('{')) commit = '@' + commit;
5763
try {
5864
if (fs.statSync(path.join(worktreePath, 'hugo.yml')).isFile()) {
5965
return { worktreePath, commit, pagePath };

0 commit comments

Comments
 (0)