Skip to content

Commit

Permalink
iterate
Browse files Browse the repository at this point in the history
  • Loading branch information
tugrulates committed Feb 28, 2025
1 parent 6367644 commit c5a64de
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
12 changes: 0 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,6 @@ jobs:
- name: Setup
uses: denoland/setup-deno@v2

- name: Git
run: |
dir=$(mktemp -d)
cd $dir
git clone https://github.com/withroka/roka.git .
echo "----"
git branch --all
echo "----"
git branch --all "--format=%(refname:short)"
echo "----"
git branch --all "--format=%(refname)"
- name: Test
run: deno task test --coverage

Expand Down
2 changes: 0 additions & 2 deletions core/git/git.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ Deno.test("git().branches.list() can return all branches", async () => {
assertEquals(await repo.branches.list({ all: true }), [
"local",
"main",
"origin/HEAD",
"origin/main",
"origin/remote",
]);
Expand All @@ -200,7 +199,6 @@ Deno.test("git().branches.list() can return only remote branches", async () => {
await using repo = await tempRepository({ clone: remote });
await repo.branches.create("local");
assertEquals(await repo.branches.list({ remotes: true }), [
"origin/HEAD",
"origin/main",
"origin/remote",
]);
Expand Down
13 changes: 11 additions & 2 deletions core/git/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@

import { pool } from "@roka/async/pool";
import { assert, assertEquals, assertFalse, assertGreater } from "@std/assert";
import { basename } from "@std/path/basename";
import { join } from "@std/path/join";

/** An error while running a git command. */
Expand Down Expand Up @@ -560,7 +561,7 @@ export function git(options?: GitOptions): Git {
async list(options) {
const branches = await run(
gitOptions,
["branch", "--list", "--format=%(refname:short)"],
["branch", "--list", "--format=%(refname)"],
options?.name,
options?.all && "--all",
options?.remotes && "--remotes",
Expand All @@ -571,7 +572,15 @@ export function git(options?: GitOptions): Git {
options?.pointsAt !== undefined &&
["--points-at", commitArg(options.pointsAt)],
);
return branches.split("\n").filter((x) => x);
// Reimplementing `refname:short`, which behaves differently on
// different git versions. This has a bug when a branch name really
// ends with `/HEAD`. This will be fixed when branches are objects.
return branches
.split("\n")
.filter((x) => x)
.filter((x) => basename(x) !== "HEAD")
.map((x) => x.replace(/^refs\/heads\//, ""))
.map((x) => x.replace(/^refs\/remotes\//, ""));
},
async checkout(options) {
await run(
Expand Down

0 comments on commit c5a64de

Please sign in to comment.