Skip to content
Open
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
39 changes: 10 additions & 29 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.88</version>
<version>5.28</version>
<relativePath />
</parent>

<groupId>io.jenkins.plugins</groupId>
<artifactId>active-git-branches</artifactId>
<version>${changelist}</version>
<artifactId>active-git-branches-plugin</artifactId>
<version>1.3.7</version>
<packaging>hpi</packaging>

<name>Active Git Branches Parameter</name>
<description>A Jenkins plugin that provides a parameter type for selecting Git branches, sorted by recent activity</description>
<url>https://github.com/jenkinsci/${project.artifactId}-plugin</url>
<url>https://github.com/litchicoder/active-git-branches-plugin</url>

<licenses>
<license>
Expand All @@ -25,40 +24,22 @@
</license>
</licenses>

<developers>
<developer>
<id>litchicoder</id>
<name>Litchi Coder</name>
</developer>
</developers>

<scm>
<connection>scm:git:https://github.com/${gitHubRepo}.git</connection>
<developerConnection>scm:git:git@github.com:${gitHubRepo}.git</developerConnection>
<url>https://github.com/${gitHubRepo}</url>
<tag>${scmTag}</tag>
</scm>

<properties>
<changelist>999999-SNAPSHOT</changelist>
<jenkins.version>2.440.3</jenkins.version>
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>
<jenkins.version>2.319.1</jenkins.version>
<java.level>11</java.level>
<gitHubRepo>jenkinsci/active-git-branches-plugin</gitHubRepo>
<enforcer.skip>true</enforcer.skip>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.440.x</artifactId>
<version>3435.v238d66a_043fb_</version>
<artifactId>bom-2.319.x</artifactId>
<version>1409.v7659b_c072f18</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.16.1</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import org.eclipse.jgit.transport.URIish;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -161,15 +162,15 @@ public List<BranchInfo> fetchBranches() {
/**
* Fetches branches from the remote Git repository.
* Strategy:
* 1. Try workspace fetch + for-each-ref (fast + time-sorted) - PREFERRED
* 1. Try workspace fetch + for-each-ref (lightweight fetch + time-sorted) - PREFERRED
* 2. If no workspace: use ls-remote (fast, alphabetical) or clone (slow, time-sorted)
*/
private List<BranchInfo> fetchBranchesInternal() throws IOException, InterruptedException {
if (repositoryUrl == null || repositoryUrl.isEmpty()) {
throw new IOException("Repository URL is not configured");
}

// First, always try workspace-based fetch (fast + preserves time sorting)
// First, always try workspace-based fetch (lightweight fetch + preserves time sorting)
List<BranchInfo> result = tryFetchFromWorkspace();
if (result != null) {
LOGGER.info("Fetched branches from workspace with time-based sorting");
Expand Down Expand Up @@ -293,8 +294,8 @@ private List<BranchInfo> tryFetchFromWorkspace() {
}

/**
* Fetch branches from an existing workspace by reading local refs only.
* No network operation - instant response.
* Fetch branches from an existing workspace.
* Performs a lightweight fetch to update refs, then reads local refs.
* Returns null if no local refs found (caller should fall back to other methods).
*/
private List<BranchInfo> fetchBranchesFromWorkspace(FilePath workspace) throws IOException, InterruptedException {
Expand All @@ -308,15 +309,23 @@ private List<BranchInfo> fetchBranchesFromWorkspace(FilePath workspace) throws I
.using("jgit")
.getClient();

// Only read existing local refs (instant, no network)
// Add credentials if available
StandardCredentials credentials = getCredentials();
if (credentials != null) {
git.addCredentials(repositoryUrl, credentials);
}

// Read cached local refs (instant, no network)
List<BranchInfo> localRefs = readLocalRefs(git);

// If we have cached refs, use them directly (fast path)
if (!localRefs.isEmpty()) {
LOGGER.info("Using cached local refs (" + localRefs.size() + " branches)");
return applyLimits(localRefs);
}

// No local refs found, return null to fall back to other methods
LOGGER.info("No local refs found in workspace, will use fallback method");
// No cached refs in workspace, return null to fall back to ls-remote
LOGGER.info("No cached refs in workspace, falling back to other method");
return null;
}

Expand Down
Loading