Ejemplo n.º 1
0
 /**
  * Creates a link to the commit diff.
  *
  * <p>https://[Gitorious
  * URL]/commit/a9182a07750c9a0dfd89a8461adf72ef5ef0885b/diffs?diffmode=sidebyside&fragment=1#[path
  * to file]
  *
  * @param path
  * @return diff link
  * @throws IOException
  */
 @Override
 public URL getDiffLink(Path path) throws IOException {
   final GitChangeSet changeSet = path.getChangeSet();
   return new URL(
       url,
       "commit/"
           + changeSet.getId().toString()
           + "/diffs?diffmode=sidebyside&fragment=1#"
           + path.getPath());
 }
Ejemplo n.º 2
0
 /**
  * Creates a link to the file diff. http://[GitWeb
  * URL]?a=blobdiff;f=[path];fp=[path];h=[dst];hp=[src];hb=[commit];hpb=[parent commit]
  *
  * @param path affected file path
  * @return diff link
  * @throws IOException
  */
 @Override
 public URL getDiffLink(Path path) throws IOException {
   if (path.getEditType() != EditType.EDIT
       || path.getSrc() == null
       || path.getDst() == null
       || path.getChangeSet().getParentCommit() == null) {
     return null;
   }
   GitChangeSet changeSet = path.getChangeSet();
   String spec =
       param()
           .add("a=blobdiff")
           .add("f=" + path.getPath())
           .add("fp=" + path.getPath())
           .add("h=" + path.getSrc())
           .add("hp=" + path.getDst())
           .add("hb=" + changeSet.getId())
           .add("hpb=" + changeSet.getParentCommit())
           .toString();
   return new URL(url, url.getPath() + spec);
 }
Ejemplo n.º 3
0
  public void testChangeSet() {
    ArrayList<String> lines = new ArrayList<String>();
    lines.add("Some header junk we should ignore...");
    lines.add("header line 2");
    lines.add("commit 123abc456def");
    lines.add("tree 789ghi012jkl");
    lines.add("parent 345mno678pqr");
    lines.add("author John Author <*****@*****.**> 1234567 -0600");
    lines.add("commiter John Committer <*****@*****.**> 1234567 -0600");
    lines.add("");
    lines.add("    Commit title.");
    lines.add("    Commit extended description.");
    lines.add("");
    lines.add(
        ":000000 123456 0000000000000000000000000000000000000000 123abc456def789abc012def345abc678def901a A\tsrc/test/add.file");
    lines.add(
        ":123456 000000 123abc456def789abc012def345abc678def901a 0000000000000000000000000000000000000000 D\tsrc/test/deleted.file");
    lines.add(
        ":123456 789012 123abc456def789abc012def345abc678def901a bc234def567abc890def123abc456def789abc01 M\tsrc/test/modified.file");
    lines.add(
        ":123456 789012 123abc456def789abc012def345abc678def901a bc234def567abc890def123abc456def789abc01 R012\tsrc/test/renamedFrom.file\tsrc/test/renamedTo.file");
    GitChangeSet changeSet = new GitChangeSet(lines);

    Assert.assertEquals("123abc456def", changeSet.getId());
    Assert.assertEquals("Commit title.", changeSet.getMsg());
    Assert.assertEquals("Commit title.\nCommit extended description.\n", changeSet.getComment());
    HashSet<String> expectedAffectedPaths = new HashSet<String>(7);
    expectedAffectedPaths.add("src/test/add.file");
    expectedAffectedPaths.add("src/test/deleted.file");
    expectedAffectedPaths.add("src/test/modified.file");
    expectedAffectedPaths.add("src/test/renamedFrom.file\tsrc/test/renamedTo.file");
    Assert.assertEquals(expectedAffectedPaths, changeSet.getAffectedPaths());

    Collection<Path> actualPaths = changeSet.getPaths();
    Assert.assertEquals(4, actualPaths.size());
    for (Path path : actualPaths) {
      if ("src/test/add.file".equals(path.getPath())) {
        Assert.assertEquals(EditType.ADD, path.getEditType());
        Assert.assertNull(path.getSrc());
        Assert.assertEquals("123abc456def789abc012def345abc678def901a", path.getDst());
      } else if ("src/test/deleted.file".equals(path.getPath())) {
        Assert.assertEquals(EditType.DELETE, path.getEditType());
        Assert.assertEquals("123abc456def789abc012def345abc678def901a", path.getSrc());
        Assert.assertNull(path.getDst());
      } else if ("src/test/modified.file".equals(path.getPath())) {
        Assert.assertEquals(EditType.EDIT, path.getEditType());
        Assert.assertEquals("123abc456def789abc012def345abc678def901a", path.getSrc());
        Assert.assertEquals("bc234def567abc890def123abc456def789abc01", path.getDst());
      } else if ("src/test/renamedFrom.file\tsrc/test/renamedTo.file".equals(path.getPath())) {
        Assert.assertEquals(EditType.EDIT, path.getEditType());
        Assert.assertNull(path.getSrc());
        Assert.assertNull(path.getDst());
      } else {
        Assert.fail("Unrecognized path.");
      }
    }
  }
Ejemplo n.º 4
0
 @Test
 public void testHashCode() {
   assertTrue(changeSet.hashCode() != 0);
 }
Ejemplo n.º 5
0
 @Test
 public void testGetTimestamp() {
   assertEquals(useAuthorName ? 1363875404000L : 1364213939000L, changeSet.getTimestamp());
 }
Ejemplo n.º 6
0
 @Test
 public void testGetDate() {
   assertEquals(
       useAuthorName ? "2013-03-21T15:16:44+0100" : "2013-03-25T08:18:59-0400",
       changeSet.getDate());
 }
Ejemplo n.º 7
0
 @Test
 public void testGetBranch() {
   assertNull(changeSet.getBranch());
 }
Ejemplo n.º 8
0
 @Test
 public void testGetAffectedFiles() {
   assertTrue(changeSet.getAffectedFiles().isEmpty());
 }
Ejemplo n.º 9
0
 @Test
 public void testGetParentCommit() {
   assertEquals(parent, changeSet.getParentCommit());
 }
Ejemplo n.º 10
0
 @Override
 public URL getChangeSetLink(GitChangeSet changeSet) throws IOException {
   return new URL(url, "commit/" + changeSet.getId().toString());
 }
 @Test
 @Issue("JENKINS-30073")
 public void testChangeSetTimeStamp() {
   assertEquals(1444148987000L, changeSet.getTimestamp());
 }
 @Test
 public void testChangeSetDate() {
   assertEquals("2015-10-06 19:29:47 +0300", changeSet.getDate());
 }
Ejemplo n.º 13
0
  @Override
  public Boolean isRevExcluded(
      GitSCM scm, GitClient git, GitChangeSet commit, TaskListener listener, BuildData buildData) {
    Collection<String> paths = commit.getAffectedPaths();
    if (paths.isEmpty()) { // nothing modified, so no need to compute any of this
      return true;
    }

    List<Pattern> included = getIncludedPatterns();
    List<Pattern> excluded = getExcludedPatterns();

    // Assemble the list of included paths
    List<String> includedPaths = new ArrayList<String>(paths.size());
    if (!included.isEmpty()) {
      for (String path : paths) {
        for (Pattern pattern : included) {
          if (pattern.matcher(path).matches()) {
            includedPaths.add(path);
            break;
          }
        }
      }
    } else {
      includedPaths.addAll(paths);
    }

    // Assemble the list of excluded paths
    List<String> excludedPaths = new ArrayList<String>();
    if (!excluded.isEmpty()) {
      for (String path : includedPaths) {
        for (Pattern pattern : excluded) {
          if (pattern.matcher(path).matches()) {
            excludedPaths.add(path);
            break;
          }
        }
      }
    }

    if (excluded.isEmpty() && !included.isEmpty() && includedPaths.isEmpty()) {
      listener
          .getLogger()
          .println(
              "Ignored commit "
                  + commit.getCommitId()
                  + ": No paths matched included region whitelist");
      return true;
    } else if (includedPaths.size() == excludedPaths.size()) {
      // If every affected path is excluded, return true.
      listener
          .getLogger()
          .println(
              "Ignored commit "
                  + commit.getCommitId()
                  + ": Found only excluded paths: "
                  + Util.join(excludedPaths, ", "));
      return true;
    }

    return null;
  }
Ejemplo n.º 14
0
 @Test
 public void testGetCommitId() {
   assertEquals(id, changeSet.getCommitId());
 }
Ejemplo n.º 15
0
 @Test
 public void testGetMsg() {
   assertEquals(msg, changeSet.getMsg());
 }
Ejemplo n.º 16
0
 @Test
 public void testSetParent() {
   changeSet.setParent(null);
   assertNull(changeSet.getParent());
 }
Ejemplo n.º 17
0
 @Test
 public void testGetRevision() {
   assertEquals(id, changeSet.getRevision());
 }
Ejemplo n.º 18
0
 @Test
 public void testGetPaths() {
   assertTrue(changeSet.getPaths().isEmpty());
 }
Ejemplo n.º 19
0
 @Test
 public void testGetComment() {
   assertTrue(changeSet.getComment().startsWith(commentStartText));
 }
Ejemplo n.º 20
0
 @Test
 public void testGetAuthorName() {
   assertEquals(useAuthorName ? authorName : committerName, changeSet.getAuthorName());
 }
Ejemplo n.º 21
0
 @Override
 public URL getChangeSetLink(GitChangeSet changeSet) throws IOException {
   return new URL(
       url, url.getPath() + param().add("a=commit").add("h=" + changeSet.getId()).toString());
 }