Просмотр исходного кода

Blame support finished, requires JGit 1.0.0. Checkstyle. Findbugs.

tags/v0.5.0
James Moger 13 лет назад
Родитель
Сommit
008322bec7
28 измененных файлов: 203 добавлений и 79 удалений
  1. 40
    0
      src/com/gitblit/models/AnnotatedLine.java
  2. 1
    1
      src/com/gitblit/models/GitNote.java
  3. 1
    1
      src/com/gitblit/models/RefModel.java
  4. 26
    0
      src/com/gitblit/utils/DiffUtils.java
  5. 2
    1
      src/com/gitblit/utils/JGitUtils.java
  6. 2
    1
      src/com/gitblit/utils/MetricUtils.java
  7. 2
    2
      src/com/gitblit/utils/StringUtils.java
  8. 2
    2
      src/com/gitblit/utils/TimeUtils.java
  9. 1
    1
      src/com/gitblit/wicket/GitBlitWebApp.java
  10. 2
    2
      src/com/gitblit/wicket/WicketUtils.java
  11. 4
    4
      src/com/gitblit/wicket/pages/BlamePage.html
  12. 59
    27
      src/com/gitblit/wicket/pages/BlamePage.java
  13. 2
    1
      src/com/gitblit/wicket/pages/BlobPage.java
  14. 2
    1
      src/com/gitblit/wicket/pages/CommitDiffPage.java
  15. 2
    2
      src/com/gitblit/wicket/pages/CommitPage.java
  16. 3
    3
      src/com/gitblit/wicket/pages/EditRepositoryPage.java
  17. 5
    5
      src/com/gitblit/wicket/pages/MetricsPage.java
  18. 4
    0
      src/com/gitblit/wicket/pages/RepositoryPage.java
  19. 7
    6
      src/com/gitblit/wicket/pages/SummaryPage.java
  20. 1
    1
      src/com/gitblit/wicket/panels/CommitHeaderPanel.java
  21. 1
    1
      src/com/gitblit/wicket/panels/CommitLegendPanel.java
  22. 2
    1
      src/com/gitblit/wicket/panels/LogPanel.java
  23. 3
    3
      src/com/gitblit/wicket/panels/TagsPanel.java
  24. 13
    0
      src/com/gitblit/wicket/resources/gitblit.css
  25. 9
    6
      tests/com/gitblit/tests/JGitUtilsTest.java
  26. 1
    1
      tests/com/gitblit/tests/MetricUtilsTest.java
  27. 4
    4
      tests/com/gitblit/tests/StringUtilsTest.java
  28. 2
    2
      tests/com/gitblit/tests/TicgitUtilsTest.java

+ 40
- 0
src/com/gitblit/models/AnnotatedLine.java Просмотреть файл

@@ -0,0 +1,40 @@
/*
* Copyright 2011 gitblit.com.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitblit.models;
import java.io.Serializable;
import java.util.Date;
import org.eclipse.jgit.revwalk.RevCommit;
public class AnnotatedLine implements Serializable {
private static final long serialVersionUID = 1L;
public final String commitId;
public final String author;
public final Date when;
public final int lineNumber;
public final String data;
public AnnotatedLine(RevCommit commit, int lineNumber, String data) {
this.commitId = commit.getName();
this.author = commit.getAuthorIdent().getName();
this.when = commit.getAuthorIdent().getWhen();
this.lineNumber = lineNumber;
this.data = data;
}
}

+ 1
- 1
src/com/gitblit/models/GitNote.java Просмотреть файл

@@ -22,7 +22,7 @@ public class GitNote implements Serializable {
private static final long serialVersionUID = 1L;
public String content;
public RefModel notesRef;
public RefModel notesRef;
public GitNote(RefModel notesRef, String text) {
this.notesRef = notesRef;

+ 1
- 1
src/com/gitblit/models/RefModel.java Просмотреть файл

@@ -127,7 +127,7 @@ public class RefModel implements Serializable, Comparable<RefModel> {
public int compareTo(RefModel o) {
return getDate().compareTo(o.getDate());
}
@Override
public String toString() {
return displayName;

+ 26
- 0
src/com/gitblit/utils/DiffUtils.java Просмотреть файл

@@ -16,10 +16,14 @@
package com.gitblit.utils;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jgit.api.BlameCommand;
import org.eclipse.jgit.blame.BlameResult;
import org.eclipse.jgit.diff.DiffEntry;
import org.eclipse.jgit.diff.DiffFormatter;
import org.eclipse.jgit.diff.RawText;
import org.eclipse.jgit.diff.RawTextComparator;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
@@ -30,6 +34,8 @@ import org.eclipse.jgit.treewalk.filter.TreeFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.gitblit.models.AnnotatedLine;
public class DiffUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(DiffUtils.class);
@@ -172,4 +178,24 @@ public class DiffUtils {
}
return null;
}
public static List<AnnotatedLine> blame(Repository r, String blobPath, String objectId) {
List<AnnotatedLine> lines = new ArrayList<AnnotatedLine>();
try {
BlameCommand blameCommand = new BlameCommand(r);
blameCommand.setFilePath(blobPath);
blameCommand.setStartCommit(r.resolve(objectId));
BlameResult blameResult = blameCommand.call();
RawText rawText = blameResult.getResultContents();
int length = rawText.size();
for (int i = 0; i < length; i++) {
RevCommit commit = blameResult.getSourceCommit(i);
AnnotatedLine line = new AnnotatedLine(commit, i + 1, rawText.getString(i));
lines.add(line);
}
} catch (Throwable t) {
LOGGER.error("failed to generate blame!", t);
}
return lines;
}
}

+ 2
- 1
src/com/gitblit/utils/JGitUtils.java Просмотреть файл

@@ -96,7 +96,8 @@ public class JGitUtils {
return r.toString().trim();
}
public static FetchResult cloneRepository(File repositoriesFolder, String name, String fromUrl) throws Exception {
public static FetchResult cloneRepository(File repositoriesFolder, String name, String fromUrl)
throws Exception {
FetchResult result = null;
if (!name.toLowerCase().endsWith(Constants.DOT_GIT_EXT)) {
name += Constants.DOT_GIT_EXT;

+ 2
- 1
src/com/gitblit/utils/MetricUtils.java Просмотреть файл

@@ -39,7 +39,8 @@ public class MetricUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(MetricUtils.class);
public static List<Metric> getDateMetrics(Repository r, String objectId, boolean includeTotal, String format) {
public static List<Metric> getDateMetrics(Repository r, String objectId, boolean includeTotal,
String format) {
Metric total = new Metric("TOTAL");
final Map<String, Metric> metricMap = new HashMap<String, Metric>();
if (StringUtils.isEmpty(objectId)) {

+ 2
- 2
src/com/gitblit/utils/StringUtils.java Просмотреть файл

@@ -134,8 +134,8 @@ public class StringUtils {
}
return "";
}
public static String getRelativePath(String basePath, String fullPath) {
public static String getRelativePath(String basePath, String fullPath) {
String relativePath = fullPath.substring(basePath.length()).replace('\\', '/');
if (relativePath.charAt(0) == '/') {
relativePath = relativePath.substring(1);

+ 2
- 2
src/com/gitblit/utils/TimeUtils.java Просмотреть файл

@@ -30,14 +30,14 @@ public class TimeUtils {
public static final long ONEYEAR = ONEDAY * 365L;
public static boolean isToday(Date date) {
return (System.currentTimeMillis() - date.getTime()) < ONEDAY;
return (System.currentTimeMillis() - date.getTime()) < ONEDAY;
}
public static boolean isYesterday(Date date) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.DATE, 1);
return (System.currentTimeMillis() - cal.getTimeInMillis()) < ONEDAY;
return (System.currentTimeMillis() - cal.getTimeInMillis()) < ONEDAY;
}
public static String duration(int days) {

+ 1
- 1
src/com/gitblit/wicket/GitBlitWebApp.java Просмотреть файл

@@ -87,7 +87,7 @@ public class GitBlitWebApp extends WebApplication {
mount("/search", SearchPage.class);
mount("/metrics", MetricsPage.class, "r");
mount("/blame", BlamePage.class, "r", "h", "f");
// setup ticket urls
mount("/tickets", TicketsPage.class, "r");
mount("/ticket", TicketPage.class, "r", "h", "f");

+ 2
- 2
src/com/gitblit/wicket/WicketUtils.java Просмотреть файл

@@ -299,7 +299,7 @@ public class WicketUtils {
WicketUtils.setHtmlTooltip(label, title);
return label;
}
public static IChartData getChartData(Collection<Metric> metrics) {
final double[] commits = new double[metrics.size()];
final double[] tags = new double[metrics.size()];
@@ -334,7 +334,7 @@ public class WicketUtils {
}
return max;
}
public static IChartData getScatterData(Collection<Metric> metrics) {
final double[] y = new double[metrics.size()];
final double[] x = new double[metrics.size()];

+ 4
- 4
src/com/gitblit/wicket/pages/BlamePage.html Просмотреть файл

@@ -19,7 +19,7 @@
<div wicket:id="breadcrumbs">[breadcrumbs]</div>
<!-- blame content -->
<table>
<table class="annotated" style="border-top: 0px; margin-bottom:5px;">
<tbody>
<tr>
<th>Commit</th>
@@ -27,9 +27,9 @@
<th>Data</th>
</tr>
<tr wicket:id="annotation">
<td><span wicket:id="commit"></span></td>
<td><span wicket:id="line"></span></td>
<td><span wicket:id="data"></span></td>
<td><span class="sha1" wicket:id="commit"></span></td>
<td><span class="sha1" wicket:id="line"></span></td>
<td><span class="sha1" wicket:id="data"></span></td>
</tr>
</tbody>
</table>

+ 59
- 27
src/com/gitblit/wicket/pages/BlamePage.java Просмотреть файл

@@ -15,8 +15,9 @@
*/
package com.gitblit.wicket.pages;
import java.io.Serializable;
import java.util.Arrays;
import java.text.DateFormat;
import java.text.MessageFormat;
import java.text.SimpleDateFormat;
import java.util.List;
import org.apache.wicket.PageParameters;
@@ -28,6 +29,11 @@ import org.apache.wicket.markup.repeater.data.ListDataProvider;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.revwalk.RevCommit;
import com.gitblit.GitBlit;
import com.gitblit.Keys;
import com.gitblit.models.AnnotatedLine;
import com.gitblit.utils.DiffUtils;
import com.gitblit.utils.StringUtils;
import com.gitblit.wicket.WicketUtils;
import com.gitblit.wicket.panels.CommitHeaderPanel;
import com.gitblit.wicket.panels.LinkPanel;
@@ -43,8 +49,7 @@ public class BlamePage extends RepositoryPage {
RevCommit commit = getCommit();
add(new BookmarkablePageLink<Void>("blobLink", BlobPage.class,
WicketUtils.newPathParameter(repositoryName, objectId,
blobPath)));
WicketUtils.newPathParameter(repositoryName, objectId, blobPath)));
add(new BookmarkablePageLink<Void>("commitLink", CommitPage.class,
WicketUtils.newObjectParameter(repositoryName, objectId)));
add(new BookmarkablePageLink<Void>("commitDiffLink", CommitDiffPage.class,
@@ -60,38 +65,65 @@ public class BlamePage extends RepositoryPage {
add(new PathBreadcrumbsPanel("breadcrumbs", repositoryName, blobPath, objectId));
List<BlameLine> blame = Arrays.asList(new BlameLine("HEAD", "1", "Under Construction"));
ListDataProvider<BlameLine> blameDp = new ListDataProvider<BlameLine>(blame);
DataView<BlameLine> blameView = new DataView<BlameLine>("annotation", blameDp) {
String format = GitBlit.getString(Keys.web.datetimestampLongFormat,
"EEEE, MMMM d, yyyy h:mm a z");
final DateFormat df = new SimpleDateFormat(format);
df.setTimeZone(getTimeZone());
List<AnnotatedLine> lines = DiffUtils.blame(getRepository(), blobPath, objectId);
ListDataProvider<AnnotatedLine> blameDp = new ListDataProvider<AnnotatedLine>(lines);
DataView<AnnotatedLine> blameView = new DataView<AnnotatedLine>("annotation", blameDp) {
private static final long serialVersionUID = 1L;
private int count;
private String lastCommitId = "";
private boolean showInitials = true;
public void populateItem(final Item<BlameLine> item) {
BlameLine entry = item.getModelObject();
item.add(new LinkPanel("commit", "list", entry.objectId, CommitPage.class,
newCommitParameter(entry.objectId)));
item.add(new Label("line", entry.line));
item.add(new Label("data", entry.data));
public void populateItem(final Item<AnnotatedLine> item) {
AnnotatedLine entry = item.getModelObject();
item.add(new Label("line", "" + entry.lineNumber));
item.add(new Label("data", StringUtils.escapeForHtml(entry.data, true))
.setEscapeModelStrings(false));
if (!lastCommitId.equals(entry.commitId)) {
lastCommitId = entry.commitId;
count++;
// show the link for first line
LinkPanel commitLink = new LinkPanel("commit", null,
getShortObjectId(entry.commitId), CommitPage.class,
newCommitParameter(entry.commitId));
WicketUtils.setHtmlTooltip(commitLink,
MessageFormat.format("{0}, {1}", entry.author, df.format(entry.when)));
item.add(commitLink);
showInitials = true;
} else {
if (showInitials) {
showInitials = false;
// show author initials
item.add(new Label("commit", getInitials(entry.author)));
} else {
// hide the commit link until the next block
item.add(new Label("commit").setVisible(false));
}
}
if (count % 2 == 0) {
WicketUtils.setCssClass(item, "even");
} else {
WicketUtils.setCssClass(item, "odd");
}
}
};
add(blameView);
}
private String getInitials(String author) {
StringBuilder sb = new StringBuilder();
String[] chunks = author.split(" ");
for (String chunk : chunks) {
sb.append(chunk.charAt(0));
}
return sb.toString().toUpperCase();
}
@Override
protected String getPageName() {
return getString("gb.blame");
}
private class BlameLine implements Serializable {
private static final long serialVersionUID = 1L;
final String objectId;
final String line;
final String data;
BlameLine(String objectId, String line, String data) {
this.objectId = objectId;
this.line = line;
this.data = data;
}
}
}

+ 2
- 1
src/com/gitblit/wicket/pages/BlobPage.java Просмотреть файл

@@ -46,7 +46,8 @@ public class BlobPage extends RepositoryPage {
// blob by objectid
add(new BookmarkablePageLink<Void>("blameLink", BlamePage.class,
WicketUtils.newPathParameter(repositoryName, objectId, blobPath)).setEnabled(false));
WicketUtils.newPathParameter(repositoryName, objectId, blobPath))
.setEnabled(false));
add(new BookmarkablePageLink<Void>("historyLink", HistoryPage.class).setEnabled(false));
add(new BookmarkablePageLink<Void>("rawLink", RawPage.class,
WicketUtils.newPathParameter(repositoryName, objectId, blobPath)));

+ 2
- 1
src/com/gitblit/wicket/pages/CommitDiffPage.java Просмотреть файл

@@ -101,7 +101,8 @@ public class CommitDiffPage extends RepositoryPage {
item.add(new BookmarkablePageLink<Void>("blame", BlamePage.class,
newPathParameter(entry.path)));
item.add(new BookmarkablePageLink<Void>("history", HistoryPage.class,
newPathParameter(entry.path)).setEnabled(!entry.changeType.equals(ChangeType.ADD)));
newPathParameter(entry.path)).setEnabled(!entry.changeType
.equals(ChangeType.ADD)));
WicketUtils.setAlternatingBackground(item, counter);
counter++;

+ 2
- 2
src/com/gitblit/wicket/pages/CommitPage.java Просмотреть файл

@@ -65,8 +65,8 @@ public class CommitPage extends RepositoryPage {
add(new Label("parentLink", "none"));
add(new Label("commitdiffLink", getString("gb.commitdiff")));
} else {
add(new LinkPanel("parentLink", null, parents.get(0).substring(0, 8), CommitPage.class,
newCommitParameter(parents.get(0))));
add(new LinkPanel("parentLink", null, getShortObjectId(parents.get(0)),
CommitPage.class, newCommitParameter(parents.get(0))));
add(new LinkPanel("commitdiffLink", null, new StringResourceModel("gb.commitdiff",
this, null), CommitDiffPage.class, WicketUtils.newObjectParameter(
repositoryName, objectId)));

+ 3
- 3
src/com/gitblit/wicket/pages/EditRepositoryPage.java Просмотреть файл

@@ -107,11 +107,11 @@ public class EditRepositoryPage extends BasePage {
repositoryModel.name = repositoryModel.name.replace("//", "/");
// prohibit folder paths
if (repositoryModel.name.startsWith("/")) {
if (repositoryModel.name.startsWith("/")) {
error("Leading root folder references (/) are prohibited.");
return;
}
if (repositoryModel.name.startsWith("../")) {
if (repositoryModel.name.startsWith("../")) {
error("Relative folder references (../) are prohibited.");
return;
}
@@ -135,7 +135,7 @@ public class EditRepositoryPage extends BasePage {
}
}
}
// confirm access restriction selection
if (repositoryModel.accessRestriction == null) {
error("Please select access restriction!");

+ 5
- 5
src/com/gitblit/wicket/pages/MetricsPage.java Просмотреть файл

@@ -46,18 +46,18 @@ import com.gitblit.wicket.WicketUtils;
public class MetricsPage extends RepositoryPage {
public MetricsPage(PageParameters params) {
super(params);
super(params);
Repository r = getRepository();
add(new Label("branchTitle", objectId));
Metric metricsTotal = null;
List<Metric> metrics = MetricUtils.getDateMetrics(r, objectId, true, null);
metricsTotal = metrics.remove(0);
if (metricsTotal == null) {
add(new Label("branchStats", ""));
add(new Label("branchStats", ""));
} else {
add(new Label("branchStats", MessageFormat.format(
"{0} commits and {1} tags in {2}", metricsTotal.count, metricsTotal.tag,
TimeUtils.duration(metricsTotal.duration))));
add(new Label("branchStats",
MessageFormat.format("{0} commits and {1} tags in {2}", metricsTotal.count,
metricsTotal.tag, TimeUtils.duration(metricsTotal.duration))));
}
insertLinePlot("commitsChart", metrics);
insertBarPlot("dayOfWeekChart", getDayOfWeekMetrics(r, objectId));

+ 4
- 0
src/com/gitblit/wicket/pages/RepositoryPage.java Просмотреть файл

@@ -218,6 +218,10 @@ public abstract class RepositoryPage extends BasePage {
return commit;
}
protected String getShortObjectId(String objectId) {
return objectId.substring(0, 8);
}
protected void addRefs(Repository r, RevCommit c) {
add(new RefsPanel("refsPanel", repositoryName, c, JGitUtils.getAllRefs(r)));
}

+ 7
- 6
src/com/gitblit/wicket/pages/SummaryPage.java Просмотреть файл

@@ -89,13 +89,14 @@ public class SummaryPage extends RepositoryPage {
add(WicketUtils.createTimestampLabel("repositoryLastChange", JGitUtils.getLastChange(r),
getTimeZone()));
if (metricsTotal == null) {
add(new Label("branchStats", ""));
add(new Label("branchStats", ""));
} else {
add(new Label("branchStats", MessageFormat.format(
"{0} commits and {1} tags in {2}", metricsTotal.count, metricsTotal.tag,
TimeUtils.duration(metricsTotal.duration))));
add(new Label("branchStats",
MessageFormat.format("{0} commits and {1} tags in {2}", metricsTotal.count,
metricsTotal.tag, TimeUtils.duration(metricsTotal.duration))));
}
add(new BookmarkablePageLink<Void>("metrics", MetricsPage.class, WicketUtils.newRepositoryParameter(repositoryName)));
add(new BookmarkablePageLink<Void>("metrics", MetricsPage.class,
WicketUtils.newRepositoryParameter(repositoryName)));
List<String> repositoryUrls = new ArrayList<String>();
@@ -203,7 +204,7 @@ public class SummaryPage extends RepositoryPage {
metrics.get(metrics.size() / 2).name, metrics.get(metrics.size() - 1).name });
provider.addAxis(dateAxis);
ChartAxis commitAxis = new ChartAxis(ChartAxisType.LEFT);
ChartAxis commitAxis = new ChartAxis(ChartAxisType.LEFT);
commitAxis.setLabels(new String[] { "",
String.valueOf((int) WicketUtils.maxValue(metrics)) });
provider.addAxis(commitAxis);

+ 1
- 1
src/com/gitblit/wicket/panels/CommitHeaderPanel.java Просмотреть файл

@@ -32,7 +32,7 @@ public class CommitHeaderPanel extends BasePanel {
add(new Label("author"));
add(new Label("date"));
}
public CommitHeaderPanel(String id, String repositoryName, RevCommit c) {
super(id);
add(new LinkPanel("shortmessage", "title", c.getShortMessage(), CommitPage.class,

+ 1
- 1
src/com/gitblit/wicket/panels/CommitLegendPanel.java Просмотреть файл

@@ -74,7 +74,7 @@ public class CommitLegendPanel extends Panel {
};
add(legendsView);
}
protected Map<ChangeType, AtomicInteger> getChangedPathsStats(List<PathChangeModel> paths) {
Map<ChangeType, AtomicInteger> stats = new HashMap<ChangeType, AtomicInteger>();
for (PathChangeModel path : paths) {

+ 2
- 1
src/com/gitblit/wicket/panels/LogPanel.java Просмотреть файл

@@ -127,7 +127,8 @@ public class LogPanel extends BasePanel {
item.add(new BookmarkablePageLink<Void>("view", CommitPage.class, WicketUtils
.newObjectParameter(repositoryName, entry.getName())));
item.add(new BookmarkablePageLink<Void>("diff", CommitDiffPage.class, WicketUtils
.newObjectParameter(repositoryName, entry.getName())).setEnabled(entry.getParentCount() > 0));
.newObjectParameter(repositoryName, entry.getName())).setEnabled(entry
.getParentCount() > 0));
item.add(new BookmarkablePageLink<Void>("tree", TreePage.class, WicketUtils
.newObjectParameter(repositoryName, entry.getName())));

+ 3
- 3
src/com/gitblit/wicket/panels/TagsPanel.java Просмотреть файл

@@ -44,7 +44,7 @@ import com.gitblit.wicket.pages.TreePage;
public class TagsPanel extends BasePanel {
private static final long serialVersionUID = 1L;
private final boolean hasTags;
public TagsPanel(String wicketId, final String repositoryName, Repository r, final int maxCount) {
@@ -164,10 +164,10 @@ public class TagsPanel extends BasePanel {
add(new LinkPanel("allTags", "link", new StringResourceModel("gb.allTags", this, null),
TagsPage.class, WicketUtils.newRepositoryParameter(repositoryName)));
}
hasTags = tags.size() > 0;
}
public TagsPanel hideIfEmpty() {
setVisible(hasTags);
return this;

+ 13
- 0
src/com/gitblit/wicket/resources/gitblit.css Просмотреть файл

@@ -633,6 +633,19 @@ table.gitnotes td.message {
border-left: 1px solid #ccc;
}
table.annotated {
width: 100%;
border: 1px solid #bbb;
}
table.annotated tr.even {
background-color: white;
}
table.annotated tr.odd {
background-color: #fdfbdf;
}
tr th a { padding-right: 15px; background-position: right; background-repeat:no-repeat; }
tr th.wicket_orderDown a {background-image: url(arrow_down.png); }
tr th.wicket_orderUp a { background-image: url(arrow_up.png); }

+ 9
- 6
tests/com/gitblit/tests/JGitUtilsTest.java Просмотреть файл

@@ -96,10 +96,11 @@ public class JGitUtilsTest extends TestCase {
public void testCreateRepository() throws Exception {
String[] repositories = { "NewTestRepository.git", "NewTestRepository" };
for (String repositoryName : repositories) {
for (String repositoryName : repositories) {
Repository repository = JGitUtils.createRepository(GitBlitSuite.REPOSITORIES,
repositoryName);
File folder = FileKey.resolve(new File(GitBlitSuite.REPOSITORIES, repositoryName), FS.DETECTED);
File folder = FileKey.resolve(new File(GitBlitSuite.REPOSITORIES, repositoryName),
FS.DETECTED);
assertTrue(repository != null);
assertFalse(JGitUtils.hasCommits(repository));
assertTrue(JGitUtils.getFirstCommit(repository, null) == null);
@@ -121,10 +122,11 @@ public class JGitUtilsTest extends TestCase {
List<RefModel> list = entry.getValue();
for (RefModel ref : list) {
if (ref.displayName.equals("refs/tags/spearce-gpg-pub")) {
assertTrue(ref.getObjectId().getName().equals("8bbde7aacf771a9afb6992434f1ae413e010c6d8"));
assertTrue(ref.getObjectId().getName()
.equals("8bbde7aacf771a9afb6992434f1ae413e010c6d8"));
assertTrue(ref.getAuthorIdent().getEmailAddress().equals("spearce@spearce.org"));
assertTrue(ref.getShortMessage().startsWith("GPG key"));
assertTrue(ref.getFullMessage().startsWith("GPG key"));
assertTrue(ref.getFullMessage().startsWith("GPG key"));
assertTrue(ref.getReferencedObjectType() == Constants.OBJ_BLOB);
} else if (ref.displayName.equals("refs/tags/v0.12.1")) {
assertTrue(ref.isAnnotatedTag());
@@ -168,13 +170,14 @@ public class JGitUtilsTest extends TestCase {
+ model.getName().hashCode());
}
repository.close();
repository = GitBlitSuite.getBluezGnomeRepository();
for (RefModel model : JGitUtils.getTags(repository, true, -1)) {
if (model.getObjectId().getName().equals("728643ec0c438c77e182898c2f2967dbfdc231c8")) {
assertFalse(model.isAnnotatedTag());
assertTrue(model.getAuthorIdent().getEmailAddress().equals("marcel@holtmann.org"));
assertTrue(model.getFullMessage().equals("Update changelog and bump version number\n"));
assertTrue(model.getFullMessage().equals(
"Update changelog and bump version number\n"));
}
}
repository.close();

+ 1
- 1
tests/com/gitblit/tests/MetricUtilsTest.java Просмотреть файл

@@ -32,7 +32,7 @@ public class MetricUtilsTest extends TestCase {
repository.close();
assertTrue("No date metrics found!", metrics.size() > 0);
}
public void testAuthorMetrics() throws Exception {
Repository repository = GitBlitSuite.getHelloworldRepository();
List<Metric> byEmail = MetricUtils.getAuthorMetrics(repository, null, true);

+ 4
- 4
tests/com/gitblit/tests/StringUtilsTest.java Просмотреть файл

@@ -38,10 +38,10 @@ public class StringUtilsTest extends TestCase {
public void testEscapeForHtml() throws Exception {
String input = "& < > \" \t";
String output_nochange = "&amp; &lt; &gt; &quot; \t";
String output_change = "&amp;&nbsp;&lt;&nbsp;&gt;&nbsp;&quot;&nbsp; &nbsp; &nbsp;";
assertTrue(StringUtils.escapeForHtml(input, false).equals(output_nochange));
assertTrue(StringUtils.escapeForHtml(input, true).equals(output_change));
String outputNoChange = "&amp; &lt; &gt; &quot; \t";
String outputChange = "&amp;&nbsp;&lt;&nbsp;&gt;&nbsp;&quot;&nbsp; &nbsp; &nbsp;";
assertTrue(StringUtils.escapeForHtml(input, false).equals(outputNoChange));
assertTrue(StringUtils.escapeForHtml(input, true).equals(outputChange));
}
public void testFlattenStrings() throws Exception {

+ 2
- 2
tests/com/gitblit/tests/TicgitUtilsTest.java Просмотреть файл

@@ -33,7 +33,7 @@ public class TicgitUtilsTest extends TestCase {
RefModel branch = TicgitUtils.getTicketsBranch(repository);
repository.close();
assertTrue("Ticgit branch does not exist!", branch != null);
repository = GitBlitSuite.getHelloworldRepository();
branch = TicgitUtils.getTicketsBranch(repository);
repository.close();
@@ -60,7 +60,7 @@ public class TicgitUtilsTest extends TestCase {
assertTrue(commentA.hashCode() == commentA.text.hashCode());
}
}
repository = GitBlitSuite.getHelloworldRepository();
List<TicketModel> ticketsC = TicgitUtils.getTickets(repository);
repository.close();

Загрузка…
Отмена
Сохранить