Skip to content

Commit

Permalink
Test to confirm JENKINS-23424 is a bug in our JGit implementation
Browse files Browse the repository at this point in the history
JENKINS-23424 reports that a tracked file which is locally modified is
not reset to its original content on the next checkout when using our
JGit implementation.  It is reset to its original content when using
our command line git implementation.
  • Loading branch information
MarkEWaite committed Jun 15, 2014
1 parent 565849d commit 48fe77d
Showing 1 changed file with 57 additions and 7 deletions.
64 changes: 57 additions & 7 deletions src/test/java/org/jenkinsci/plugins/gitclient/GitAPITestCase.java
Expand Up @@ -5,7 +5,6 @@
import org.apache.commons.lang.SystemUtils;
import org.apache.commons.lang.StringUtils;

import com.gargoylesoftware.htmlunit.ProxyConfig;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
Expand All @@ -22,8 +21,6 @@
import hudson.plugins.git.IGitAPI;
import hudson.plugins.git.IndexEntry;
import hudson.remoting.VirtualChannel;
import hudson.util.IOException2;
import hudson.util.ReflectionUtils;
import hudson.util.StreamTaskListener;
import junit.framework.TestCase;

Expand All @@ -40,8 +37,6 @@
import org.eclipse.jgit.transport.URIish;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.TemporaryDirectoryAllocator;
import org.objenesis.Objenesis;
import org.objenesis.ObjenesisBase;
import org.objenesis.ObjenesisStd;

import java.io.*;
Expand All @@ -56,8 +51,6 @@
import java.util.TreeSet;
import java.util.UUID;

import jenkins.model.Jenkins;

/**
* @author <a href="mailto:nicolas.deloof@gmail.com">Nicolas De Loof</a>
*/
Expand Down Expand Up @@ -1347,6 +1340,63 @@ public void test_trackingSubmodule() throws Exception {
assertTrue("file2 does not exist and should because we updated to the top of the branch (master).", w.exists(subFile));
}

/* Check JENKINS-23424 - inconsistent handling of modified tracked
* files when performing a checkout in an existing directory.
* CliGitAPIImpl reverts tracked files, while JGitAPIImpl does
* not.
*/
private void base_checkout_replaces_tracked_changes(boolean defineBranch) throws Exception {
w.git.clone_().url(localMirror()).repositoryName("JENKINS-23424").execute();
w.adaptCliGitClone("JENKINS-23424");
if (defineBranch) {
w.git.checkout().branch("master").ref("JENKINS-23424/master").deleteBranchIfExist(true).execute();
} else {
w.git.checkout().ref("JENKINS-23424/master").deleteBranchIfExist(true).execute();
}

/* Confirm first checkout */
String pomContent = w.contentOf("pom.xml");
assertTrue("Missing jacoco ref in master pom : " + pomContent, pomContent.contains("jacoco"));
assertFalse("Found untracked file", w.file("untracked-file").exists());

/* Modify the pom file by adding a comment */
String comment = " <!-- JENKINS-23424 comment -->";
if (w.git instanceof CliGitAPIImpl) {
/* JGit implementation does not reset modified tracked files */
w.touch("pom.xml", pomContent + comment);
assertTrue(w.contentOf("pom.xml").contains(comment));
}

/* Create an untracked file. Both implementations retain
* untracked files across checkout.
*/
w.touch("untracked-file", comment);
assertTrue("Missing untracked file", w.file("untracked-file").exists());

/* Checkout should erase local modification */
if (defineBranch) {
w.git.checkout().branch("1.4.x").ref("JENKINS-23424/1.4.x").deleteBranchIfExist(true).execute();
} else {
w.git.checkout().ref("JENKINS-23424/1.4.x").deleteBranchIfExist(true).execute();
}

/* Tracked file should not contain added comment, nor the jacoco reference */
pomContent = w.contentOf("pom.xml");
assertFalse("Found jacoco ref in 1.4.x pom : " + pomContent, pomContent.contains("jacoco"));
assertFalse("Found comment in 1.4.x pom", pomContent.contains(comment));
assertTrue("Missing untracked file", w.file("untracked-file").exists());
}

@Bug(23424)
public void test_checkout_replaces_tracked_changes() throws Exception {
base_checkout_replaces_tracked_changes(false);
}

@Bug(23424)
public void test_checkout_replaces_tracked_changes_with_branch() throws Exception {
base_checkout_replaces_tracked_changes(true);
}

/**
* Confirm that JENKINS-8122 is fixed in the current
* implementation. That bug reported that the tags from a
Expand Down

0 comments on commit 48fe77d

Please sign in to comment.