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
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (C) 2026, hanweiwei and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0 which is available at
* https://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package org.eclipse.jgit.api;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.util.List;

import org.junit.Test;

public class RebaseResultTest {

@Test
public void toStringOk() {
String s = RebaseResult.OK_RESULT.toString();
assertNotNull(s);
assertTrue(s.contains("status=OK"));
assertTrue(s.startsWith("RebaseResult["));
assertTrue(s.endsWith("]"));
}

@Test
public void toStringUpToDate() {
String s = RebaseResult.UP_TO_DATE_RESULT.toString();
assertTrue(s.contains("status=UP_TO_DATE"));
}

@Test
public void toStringFastForward() {
String s = RebaseResult.FAST_FORWARD_RESULT.toString();
assertTrue(s.contains("status=FAST_FORWARD"));
}

@Test
public void toStringConflicts() {
RebaseResult result = RebaseResult.conflicts(
List.of("file1.txt", "file2.txt"));
String s = result.toString();
assertTrue(s.contains("status=CONFLICTS"));
assertTrue(s.contains("file1.txt"));
assertTrue(s.contains("file2.txt"));
}

@Test
public void toStringUncommittedChanges() {
RebaseResult result = RebaseResult.uncommittedChanges(
List.of("dirty.java"));
String s = result.toString();
assertTrue(s.contains("status=UNCOMMITTED_CHANGES"));
assertTrue(s.contains("dirty.java"));
}

@Test
public void toStringAborted() {
String s = RebaseResult.ABORTED_RESULT.toString();
assertTrue(s.contains("status=ABORTED"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (C) 2026, hanweiwei and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0 which is available at
* https://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package org.eclipse.jgit.transport;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.util.Collections;

import org.junit.Test;

public class FetchResultTest {

@Test
public void toStringEmpty() {
FetchResult result = new FetchResult();
String s = result.toString();
assertNotNull(s);
assertTrue(s.startsWith("FetchResult["));
assertTrue(s.contains("0 ref update(s)"));
assertTrue(s.endsWith("]"));
}

@Test
public void toStringWithUri() throws Exception {
FetchResult result = new FetchResult();
result.setAdvertisedRefs(new URIish("https://example.com/repo.git"),
Collections.emptyMap());
String s = result.toString();
assertTrue(s.contains("example.com"));
}

@Test
public void toStringWithSubmodule() {
FetchResult result = new FetchResult();
result.addSubmodule("sub/path", new FetchResult());
String s = result.toString();
assertTrue(s.contains("1 submodule(s)"));
}
}
21 changes: 21 additions & 0 deletions org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -303,4 +303,25 @@ public List<String> getUncommittedChanges() {
return uncommittedChanges;
}

@SuppressWarnings("nls")
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("RebaseResult[status=").append(status);
if (currentCommit != null) {
sb.append(", currentCommit=")
.append(currentCommit.abbreviate(7).name());
}
if (conflicts != null && !conflicts.isEmpty()) {
sb.append(", conflicts=").append(conflicts);
}
if (failingPaths != null && !failingPaths.isEmpty()) {
sb.append(", failingPaths=").append(failingPaths.keySet());
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have found that for large repos it is possible for the failing paths and uncommitted changes to be very large. and therefore not suitable for adding to a to-string without summarisation.

}
if (uncommittedChanges != null && !uncommittedChanges.isEmpty()) {
sb.append(", uncommittedChanges=").append(uncommittedChanges);
}
sb.append("]");
return sb.toString();
}
}
24 changes: 24 additions & 0 deletions org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,28 @@ public void addSubmodule(String path, FetchResult result) {
public Map<String, FetchResult> submoduleResults() {
return Collections.unmodifiableMap(submodules);
}

@SuppressWarnings("nls")
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("FetchResult[");
if (uri != null) {
sb.append(uri);
}
sb.append(": ");
sb.append(updates.size()).append(" ref update(s)");
if (!forMerge.isEmpty()) {
sb.append(", ").append(forMerge.size()).append(" for merge");
}
if (!submodules.isEmpty()) {
sb.append(", ").append(submodules.size()).append(" submodule(s)");
}
String msgs = getMessages();
if (!msgs.isEmpty()) {
sb.append(", messages: ").append(msgs.trim());
}
sb.append("]");
return sb.toString();
}
}