Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/pull_requests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:

cancel-previous-runs:
name: Cancel Previous Runs
runs-on: [ ubuntu-20.04 ]
runs-on: ubuntu-latest

steps:
- name: Cancel Previous Runs
Expand All @@ -20,7 +20,7 @@ jobs:

check-commit-message:
name: Check Commit Message
runs-on: [ ubuntu-20.04 ]
runs-on: ubuntu-latest
steps:
- name: Check commit message line length
uses: gsactions/commit-message-checker@16fa2d5de096ae0d35626443bcd24f1e756cafee # v2.0.0
Expand All @@ -44,7 +44,7 @@ jobs:
gradle:
name: Gradle Build
needs: cancel-previous-runs
runs-on: [ ubuntu-20.04 ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package sims.michael.gitjaspr

import org.eclipse.jgit.lib.Constants
import org.slf4j.LoggerFactory
import org.zeroturnaround.exec.ProcessExecutor
import org.zeroturnaround.exec.ProcessResult
Expand Down Expand Up @@ -133,7 +134,7 @@ class CliGitClient(
.mapNotNull { line ->
val (nameWithRemote, hash) = line.split(GIT_FORMAT_SEPARATOR)
val (thisRemoteName, name) = nameWithRemote.split("/", limit = 2)
if (thisRemoteName == remoteName) {
if (thisRemoteName == remoteName && name != Constants.HEAD) {
RemoteBranch(name, log(hash, 1).single())
} else {
null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ class JGitClient(
.setListMode(ListBranchCommand.ListMode.REMOTE)
.call()
.filter { it.name.startsWith(Constants.R_REMOTES) }
.filterNot { ref -> ref.name == Constants.R_REMOTES + "$remoteName/HEAD" }
.mapNotNull { ref ->
val r = git.repository
val (thisRemoteName, shortBranchName) =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package sims.michael.gitjaspr

import org.eclipse.jgit.lib.Constants
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
Expand Down Expand Up @@ -367,6 +368,51 @@ class CliGitClientTest {
}
}

@Test
fun `getRemoteBranches should not include HEAD`() {
// If we've pushed to HEAD, ensure that getRemoteBranches does not return it. At some point git changed its
// behavior to include HEAD in the list of remote branches, which we don't want.
withTestSetup {
createCommitsFrom(
testCase {
repository {
commit {
title = "one"
branch {
commit { title = "a" }
commit { title = "b" }
commit { title = "c" }
commit {
title = "d"
localRefs += "development"
}
}
}
commit { title = "two" }
commit {
title = "three"
body = "This is a body"
remoteRefs += listOf(
"main",
Constants.HEAD,
)
}
}
},
)
val cliGit = CliGitClient(localGit.workingDirectory)
val git = JGitClient(localGit.workingDirectory)
assertFalse(
cliGit.getRemoteBranches(remoteName).any { branch -> branch.name.endsWith("/${Constants.HEAD}") },
"List of remote branches should not be empty",
)
assertEquals(
cliGit.getRemoteBranches(remoteName),
git.getRemoteBranches(remoteName),
)
}
}

@Test
fun `compare getRemoteBranches`() {
withTestSetup {
Expand All @@ -389,16 +435,23 @@ class CliGitClientTest {
commit {
title = "three"
body = "This is a body"
remoteRefs += "main"
remoteRefs += listOf(
"main",
Constants.HEAD,
)
}
}
},
)
val cliGit = CliGitClient(localGit.workingDirectory)
val git = JGitClient(localGit.workingDirectory)
assertFalse(
cliGit.getRemoteBranches(remoteName).isEmpty(),
"List of remote branches should not be empty",
)
assertEquals(
cliGit.getRemoteBranches(),
git.getRemoteBranches(),
cliGit.getRemoteBranches(remoteName),
git.getRemoteBranches(remoteName),
)
}
}
Expand Down Expand Up @@ -444,9 +497,13 @@ class CliGitClientTest {
)
val cliGit = CliGitClient(localGit.workingDirectory)
val git = JGitClient(localGit.workingDirectory)
assertFalse(
cliGit.getRemoteBranchesById(remoteName).isEmpty(),
"Map of remote branches should not be empty",
)
assertEquals(
cliGit.getRemoteBranchesById(),
git.getRemoteBranchesById(),
cliGit.getRemoteBranchesById(remoteName),
git.getRemoteBranchesById(remoteName),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ import java.io.File
*/
fun File.toStringWithClickableURI(): String = "$this (${toURI().toString().replaceFirst("/", "///")})"

val DEFAULT_COMMITTER: Ident = Ident("Frank Grimes", "grimey@springfield.example.com")
val DEFAULT_COMMITTER: Ident = Ident("Frank Grimes", "grimey@example.com")
Loading