1 files added
16 files modified
| | |
| | | handler = rootContext;
|
| | | }
|
| | |
|
| | | logger.info("Git repositories folder " + new File(params.repositoriesFolder).getAbsolutePath());
|
| | | logger.info("Git repositories folder "
|
| | | + new File(params.repositoriesFolder).getAbsolutePath());
|
| | |
|
| | | // Set the server's contexts
|
| | | server.setHandler(handler);
|
| | |
| | | private static final Logger LOGGER = LoggerFactory.getLogger(DiffUtils.class);
|
| | |
|
| | | public static String getCommitDiff(Repository r, RevCommit commit, DiffOutputType outputType) {
|
| | | return getCommitDiff(r, null, commit, null, outputType);
|
| | | return getDiff(r, null, commit, null, outputType);
|
| | | }
|
| | |
|
| | | public static String getCommitDiff(Repository r, RevCommit commit, String path,
|
| | | public static String getDiff(Repository r, RevCommit commit, String path,
|
| | | DiffOutputType outputType) {
|
| | | return getCommitDiff(r, null, commit, path, outputType);
|
| | | return getDiff(r, null, commit, path, outputType);
|
| | | }
|
| | |
|
| | | public static String getCommitDiff(Repository r, RevCommit baseCommit, RevCommit commit,
|
| | | public static String getDiff(Repository r, RevCommit baseCommit, RevCommit commit,
|
| | | DiffOutputType outputType) {
|
| | | return getCommitDiff(r, baseCommit, commit, null, outputType);
|
| | | return getDiff(r, baseCommit, commit, null, outputType);
|
| | | }
|
| | |
|
| | | public static String getCommitDiff(Repository r, RevCommit baseCommit, RevCommit commit,
|
| | | String path, DiffOutputType outputType) {
|
| | | public static String getDiff(Repository r, RevCommit baseCommit, RevCommit commit, String path,
|
| | | DiffOutputType outputType) {
|
| | | try {
|
| | | RevTree baseTree;
|
| | | if (baseCommit == null) {
|
| | |
| | | String diff;
|
| | | if (StringUtils.isEmpty(baseObjectId)) {
|
| | | // use first parent
|
| | | diff = DiffUtils.getCommitDiff(r, commit, blobPath, diffType);
|
| | | diff = DiffUtils.getDiff(r, commit, blobPath, diffType);
|
| | | add(new BookmarkablePageLink<Void>("patchLink", PatchPage.class,
|
| | | WicketUtils.newPathParameter(repositoryName, objectId, blobPath)));
|
| | | } else {
|
| | | // base commit specified
|
| | | RevCommit baseCommit = JGitUtils.getCommit(r, baseObjectId);
|
| | | diff = DiffUtils.getCommitDiff(r, baseCommit, commit, blobPath, diffType);
|
| | | diff = DiffUtils.getDiff(r, baseCommit, commit, blobPath, diffType);
|
| | | add(new BookmarkablePageLink<Void>("patchLink", PatchPage.class,
|
| | | WicketUtils.newBlobDiffParameter(repositoryName, baseObjectId, objectId,
|
| | | blobPath)));
|
New file |
| | |
| | | /*
|
| | | * 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.tests;
|
| | |
|
| | | import junit.framework.TestCase;
|
| | |
|
| | | import org.eclipse.jgit.lib.Repository;
|
| | | import org.eclipse.jgit.revwalk.RevCommit;
|
| | |
|
| | | import com.gitblit.utils.DiffUtils;
|
| | | import com.gitblit.utils.JGitUtils;
|
| | | import com.gitblit.utils.JGitUtils.DiffOutputType;
|
| | |
|
| | | public class DiffUtilsTest extends TestCase {
|
| | |
|
| | | public void testParentCommitDiff() throws Exception {
|
| | | Repository repository = GitBlitSuite.getHelloworldRepository();
|
| | | RevCommit commit = JGitUtils.getCommit(repository,
|
| | | "1d0c2933a4ae69c362f76797d42d6bd182d05176");
|
| | | String diff = DiffUtils.getCommitDiff(repository, commit, DiffOutputType.PLAIN);
|
| | | repository.close();
|
| | | assertTrue(diff != null && diff.length() > 0);
|
| | | String expected = "- system.out.println(\"Hello World\");\n+ System.out.println(\"Hello World\"";
|
| | | assertTrue(diff.indexOf(expected) > -1);
|
| | | }
|
| | |
|
| | | public void testArbitraryCommitDiff() throws Exception {
|
| | | Repository repository = GitBlitSuite.getHelloworldRepository();
|
| | | RevCommit baseCommit = JGitUtils.getCommit(repository,
|
| | | "8baf6a833b5579384d9b9ceb8a16b5d0ea2ec4ca");
|
| | | RevCommit commit = JGitUtils.getCommit(repository,
|
| | | "1d0c2933a4ae69c362f76797d42d6bd182d05176");
|
| | | String diff = DiffUtils.getDiff(repository, baseCommit, commit, DiffOutputType.PLAIN);
|
| | | repository.close();
|
| | | assertTrue(diff != null && diff.length() > 0);
|
| | | String expected = "- system.out.println(\"Hello World\");\n+ System.out.println(\"Hello World\"";
|
| | | assertTrue(diff.indexOf(expected) > -1);
|
| | | }
|
| | |
|
| | | public void testPlainFileDiff() throws Exception {
|
| | | Repository repository = GitBlitSuite.getHelloworldRepository();
|
| | | RevCommit commit = JGitUtils.getCommit(repository,
|
| | | "1d0c2933a4ae69c362f76797d42d6bd182d05176");
|
| | | String diff = DiffUtils.getDiff(repository, commit, "java.java", DiffOutputType.PLAIN);
|
| | | repository.close();
|
| | | assertTrue(diff != null && diff.length() > 0);
|
| | | String expected = "- system.out.println(\"Hello World\");\n+ System.out.println(\"Hello World\"";
|
| | | assertTrue(diff.indexOf(expected) > -1);
|
| | | }
|
| | |
|
| | | public void testFilePatch() throws Exception {
|
| | | Repository repository = GitBlitSuite.getHelloworldRepository();
|
| | | RevCommit commit = JGitUtils.getCommit(repository,
|
| | | "1d0c2933a4ae69c362f76797d42d6bd182d05176");
|
| | | String patch = DiffUtils.getCommitPatch(repository, null, commit, "java.java");
|
| | | repository.close();
|
| | | assertTrue(patch != null && patch.length() > 0);
|
| | | String expected = "- system.out.println(\"Hello World\");\n+ System.out.println(\"Hello World\"";
|
| | | assertTrue(patch.indexOf(expected) > -1);
|
| | | }
|
| | |
|
| | | public void testArbitraryFilePatch() throws Exception {
|
| | | Repository repository = GitBlitSuite.getHelloworldRepository();
|
| | | RevCommit baseCommit = JGitUtils.getCommit(repository,
|
| | | "8baf6a833b5579384d9b9ceb8a16b5d0ea2ec4ca");
|
| | | RevCommit commit = JGitUtils.getCommit(repository,
|
| | | "1d0c2933a4ae69c362f76797d42d6bd182d05176");
|
| | | String patch = DiffUtils.getCommitPatch(repository, baseCommit, commit, "java.java");
|
| | | repository.close();
|
| | | assertTrue(patch != null && patch.length() > 0);
|
| | | String expected = "- system.out.println(\"Hello World\");\n+ System.out.println(\"Hello World\"";
|
| | | assertTrue(patch.indexOf(expected) > -1);
|
| | | }
|
| | |
|
| | | public void testArbitraryCommitPatch() throws Exception {
|
| | | Repository repository = GitBlitSuite.getHelloworldRepository();
|
| | | RevCommit baseCommit = JGitUtils.getCommit(repository,
|
| | | "8baf6a833b5579384d9b9ceb8a16b5d0ea2ec4ca");
|
| | | RevCommit commit = JGitUtils.getCommit(repository,
|
| | | "1d0c2933a4ae69c362f76797d42d6bd182d05176");
|
| | | String patch = DiffUtils.getCommitPatch(repository, baseCommit, commit, null);
|
| | | repository.close();
|
| | | assertTrue(patch != null && patch.length() > 0);
|
| | | String expected = "- system.out.println(\"Hello World\");\n+ System.out.println(\"Hello World\"";
|
| | | assertTrue(patch.indexOf(expected) > -1);
|
| | | }
|
| | | }
|
| | |
| | | suite.addTestSuite(StringUtilsTest.class);
|
| | | suite.addTestSuite(ByteFormatTest.class);
|
| | | suite.addTestSuite(JGitUtilsTest.class);
|
| | | suite.addTestSuite(DiffUtilsTest.class);
|
| | | suite.addTestSuite(GitBlitTest.class);
|
| | | return new GitBlitSuite(suite);
|
| | | }
|
| | |
| | | public void testRepositoryModel() throws Exception {
|
| | | List<String> repositories = GitBlit.self().getRepositoryList();
|
| | | assertTrue("Repository list is empty!", repositories.size() > 0);
|
| | | assertTrue("Missing Helloworld repository!", repositories.contains(GitBlitSuite.getHelloworldRepository().getDirectory().getName()));
|
| | | RepositoryModel model = GitBlit.self().getRepositoryModel(GitBlitSuite.getHelloworldRepository().getDirectory().getName());
|
| | | assertTrue(
|
| | | "Missing Helloworld repository!",
|
| | | repositories.contains(GitBlitSuite.getHelloworldRepository().getDirectory()
|
| | | .getName()));
|
| | | RepositoryModel model = GitBlit.self().getRepositoryModel(
|
| | | GitBlitSuite.getHelloworldRepository().getDirectory().getName());
|
| | | assertTrue("Helloworld model is null!", model != null);
|
| | | assertTrue(model.toString().equals(GitBlitSuite.getHelloworldRepository().getDirectory().getName()));
|
| | | assertTrue(model.toString().equals(
|
| | | GitBlitSuite.getHelloworldRepository().getDirectory().getName()));
|
| | | }
|
| | |
|
| | | public void testUserModel() throws Exception {
|
| | |
| | | import com.gitblit.models.RefModel;
|
| | | import com.gitblit.models.TicketModel;
|
| | | import com.gitblit.models.TicketModel.Comment;
|
| | | import com.gitblit.utils.DiffUtils;
|
| | | import com.gitblit.utils.JGitUtils;
|
| | | import com.gitblit.utils.JGitUtils.DiffOutputType;
|
| | |
|
| | | public class JGitUtilsTest extends TestCase {
|
| | |
|
| | |
| | | public void testFirstCommit() throws Exception {
|
| | | Repository repository = GitBlitSuite.getHelloworldRepository();
|
| | | RevCommit commit = JGitUtils.getFirstCommit(repository, null);
|
| | | Date firstChange = JGitUtils.getFirstChange(repository, null);
|
| | | repository.close();
|
| | | assertTrue("Could not get first commit!", commit != null);
|
| | | assertTrue("Incorrect first commit!",
|
| | | commit.getName().equals("f554664a346629dc2b839f7292d06bad2db4aece"));
|
| | | assertTrue(firstChange.equals(new Date(commit.getCommitTime() * 1000L)));
|
| | | }
|
| | |
|
| | | public void testRefs() throws Exception {
|
| | |
| | | assertTrue("PathChangeModel equals itself failed!", path.equals(path));
|
| | | assertFalse("PathChangeModel equals string failed!", path.equals(""));
|
| | | }
|
| | | }
|
| | |
|
| | | public void testCommitDiff() throws Exception {
|
| | | Repository repository = GitBlitSuite.getHelloworldRepository();
|
| | | RevCommit commit = JGitUtils.getCommit(repository,
|
| | | "1d0c2933a4ae69c362f76797d42d6bd182d05176");
|
| | | String diff = DiffUtils.getCommitDiff(repository, commit, DiffOutputType.PLAIN);
|
| | | repository.close();
|
| | | assertTrue("Failed to generate diff!", diff != null && diff.length() > 0);
|
| | | String expected = "- system.out.println(\"Hello World\");\n+ System.out.println(\"Hello World\"";
|
| | | assertTrue("Diff content mismatch!", diff.indexOf(expected) > -1);
|
| | | }
|
| | |
|
| | | public void testZip() throws Exception {
|
| | |
| | | }
|
| | |
|
| | | public void testSHA1() throws Exception {
|
| | | assertTrue(StringUtils.getSHA1("blob 16\000what is up, doc?").equals("bd9dbf5aae1a3862dd1526723246b20206e5fc37"));
|
| | | assertTrue(StringUtils.getSHA1("blob 16\000what is up, doc?").equals(
|
| | | "bd9dbf5aae1a3862dd1526723246b20206e5fc37"));
|
| | | }
|
| | |
|
| | | public void testRootPath() throws Exception {
|