private void removeDeletedBranches (Map<String, GitBranch> branches) { Set<String> localBranches = new HashSet<>(); for (Map.Entry<String, GitBranch> b : branches.entrySet()) { if (!b.getValue().isRemote() && !b.getKey().equals(GitBranch.NO_BRANCH)) { localBranches.add(b.getKey()); } } if (!localBranches.equals(cachedBranches)) { cachedBranches = localBranches; List<String> toRemove = new ArrayList<>(config.getSubsections(ConfigConstants.CONFIG_BRANCH_SECTION)); boolean save = false; for (String branchName : toRemove) { if (!localBranches.contains(branchName)) { config.unsetSection(ConfigConstants.CONFIG_BRANCH_SECTION, branchName); save = true; } } if (save) { save(); } } }
@Override protected void run () throws GitException { Repository repository = getRepository(); StoredConfig config = repository.getConfig(); config.unsetSection(ConfigConstants.CONFIG_REMOTE_SECTION, remote); Set<String> subSections = config.getSubsections(ConfigConstants.CONFIG_BRANCH_SECTION); for (String subSection : subSections) { if (remote.equals(config.getString(ConfigConstants.CONFIG_BRANCH_SECTION, subSection, ConfigConstants.CONFIG_KEY_REMOTE))) { config.unset(ConfigConstants.CONFIG_BRANCH_SECTION, subSection, ConfigConstants.CONFIG_KEY_REMOTE); config.unset(ConfigConstants.CONFIG_BRANCH_SECTION, subSection, ConfigConstants.CONFIG_KEY_MERGE); } } try { config.save(); } catch (IOException ex) { throw new GitException(ex); } }
public static GitBranch getTrackedBranch (Config config, String branchName, Map<String, GitBranch> allBranches) { String remoteName = config.getString(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_REMOTE); String trackedBranchName = config.getString(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_MERGE); if (trackedBranchName != null) { if (trackedBranchName.startsWith(Constants.R_HEADS)) { trackedBranchName = trackedBranchName.substring(Constants.R_HEADS.length()); } else if (trackedBranchName.startsWith(Constants.R_REMOTES)) { trackedBranchName = trackedBranchName.substring(Constants.R_REMOTES.length()); } } if (trackedBranchName == null) { return null; } else { if (remoteName != null && ".".equals(remoteName)) { //NOI18N remoteName = ""; //NOI18N } else { remoteName = remoteName + "/"; //NOI18N } return allBranches.get(remoteName + trackedBranchName); } }
public void test199443_GlobalIgnoreFile () throws Exception { File f = new File(new File(workDir, "nbproject"), "file"); f.getParentFile().mkdirs(); f.createNewFile(); File ignoreFile = new File(workDir.getParentFile(), "globalignore"); write(ignoreFile, ".DS_Store\n.svn\nnbproject\nnbproject/private\n"); Repository repo = getRepository(getLocalGitRepository()); StoredConfig cfg = repo.getConfig(); cfg.setString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_EXCLUDESFILE, ignoreFile.getAbsolutePath()); cfg.save(); GitClient client = getClient(workDir); assertEquals(Status.STATUS_IGNORED, client.getStatus(new File[] { f }, NULL_PROGRESS_MONITOR).get(f).getStatusIndexWC()); // now since the file is already ignored, no ignore file should be modified assertEquals(0, client.ignore(new File[] { f }, NULL_PROGRESS_MONITOR).length); // on the other hand, if .git/info/exclude reverts the effect of global excludes file, ignored file should be modified File dotGitIgnoreFile = new File(new File(repo.getDirectory(), "info"), "exclude"); dotGitIgnoreFile.getParentFile().mkdirs(); write(dotGitIgnoreFile, "!/nbproject/"); assertEquals(Status.STATUS_ADDED, client.getStatus(new File[] { f }, NULL_PROGRESS_MONITOR).get(f).getStatusIndexWC()); assertEquals(dotGitIgnoreFile, client.ignore(new File[] { f }, NULL_PROGRESS_MONITOR)[0]); assertEquals(Status.STATUS_IGNORED, client.getStatus(new File[] { f }, NULL_PROGRESS_MONITOR).get(f).getStatusIndexWC()); }
public void test199443_GlobalIgnoreFileOverwrite () throws Exception { File f = new File(new File(workDir, "nbproject"), "file"); f.getParentFile().mkdirs(); f.createNewFile(); File ignoreFile = new File(workDir.getParentFile(), "globalignore"); Repository repo = getRepository(getLocalGitRepository()); StoredConfig cfg = repo.getConfig(); cfg.setString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_EXCLUDESFILE, ignoreFile.getAbsolutePath()); cfg.save(); write(ignoreFile, "!nbproject"); GitClient client = getClient(workDir); assertEquals(new File(workDir, Constants.GITIGNORE_FILENAME), client.ignore(new File[] { f }, NULL_PROGRESS_MONITOR)[0]); assertEquals("/nbproject/file", read(new File(workDir, Constants.GITIGNORE_FILENAME))); }
public void testRemoteTrackingNoRemoteSet () throws GitException { GitClient client = getClient(workDir); File f = new File(workDir, "f"); add(f); client.commit(new File[] { f }, "init commit", null, null, NULL_PROGRESS_MONITOR); // push to remote String remoteUri = getRemoteRepository().getWorkTree().toURI().toString(); client.push(remoteUri, Arrays.asList("refs/heads/master:refs/heads/master"), Arrays.asList("+refs/heads/*:refs/remotes/origin/*"), NULL_PROGRESS_MONITOR); Map<String, GitBranch> branches = client.getBranches(true, NULL_PROGRESS_MONITOR); assertTrue(branches.containsKey("origin/master")); assertNull(branches.get("master").getTrackedBranch()); // set tracking GitBranch b = client.setUpstreamBranch("master", "origin/master", NULL_PROGRESS_MONITOR); assertEquals("origin/master", b.getTrackedBranch().getName()); Config cfg = repository.getConfig(); assertEquals(".", cfg.getString(ConfigConstants.CONFIG_BRANCH_SECTION, "master", ConfigConstants.CONFIG_KEY_REMOTE)); assertEquals("refs/remotes/origin/master", cfg.getString(ConfigConstants.CONFIG_BRANCH_SECTION, "master", ConfigConstants.CONFIG_KEY_MERGE)); }
public void testDeleteUntrackedLocalBranch () throws Exception { File f = new File(workDir, "f"); File[] files = { f }; write(f, "init"); add(files); commit(files); GitClient client = getClient(workDir); GitBranch b = client.createBranch(BRANCH_NAME, "master", NULL_PROGRESS_MONITOR); Map<String, GitBranch> branches = client.getBranches(false, NULL_PROGRESS_MONITOR); assertEquals(2, branches.size()); assertNotNull(branches.get(BRANCH_NAME)); assertEquals(0, repository.getConfig().getSubsections(ConfigConstants.CONFIG_BRANCH_SECTION).size()); // delete branch client.deleteBranch(BRANCH_NAME, false, NULL_PROGRESS_MONITOR); branches = client.getBranches(false, NULL_PROGRESS_MONITOR); assertEquals(1, branches.size()); assertNull(branches.get(BRANCH_NAME)); }
public void testMergeBranchNoHeadYet_196837 () throws Exception { StoredConfig cfg = getRemoteRepository().getConfig(); cfg.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_BARE, false); cfg.save(); File otherRepo = getRemoteRepository().getWorkTree(); File original = new File(otherRepo, "f"); GitClient clientOtherRepo = getClient(otherRepo); write(original, "initial content"); clientOtherRepo.add(new File[] { original }, NULL_PROGRESS_MONITOR); clientOtherRepo.commit(new File[] { original }, "initial commit", null, null, NULL_PROGRESS_MONITOR); GitClient client = getClient(workDir); Map<String, GitTransportUpdate> updates = client.fetch(otherRepo.toURI().toString(), Arrays.asList(new String[] { "+refs/heads/master:refs/remotes/origin/master" }), NULL_PROGRESS_MONITOR); GitMergeResult result = client.merge("origin/master", NULL_PROGRESS_MONITOR); assertEquals(MergeStatus.FAST_FORWARD, result.getMergeStatus()); assertEquals(Arrays.asList(new String[] { ObjectId.zeroId().getName(), updates.get("origin/master").getNewObjectId() }), Arrays.asList(result.getMergedCommits())); }
public void testAddIgnoreExecutable () throws Exception { if (isWindows()) { // no reason to test on windows return; } File f = new File(workDir, "f"); write(f, "hi, i am executable"); f.setExecutable(true); File[] roots = { f }; GitClient client = getClient(workDir); StoredConfig config = repository.getConfig(); config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_FILEMODE, false); config.save(); // add should not set executable bit in index add(roots); Map<File, GitStatus> statuses = client.getStatus(roots, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, f, true, Status.STATUS_ADDED, Status.STATUS_NORMAL, Status.STATUS_ADDED, false); // index should differ from wt config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_FILEMODE, true); config.save(); statuses = client.getStatus(roots, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, f, true, Status.STATUS_ADDED, Status.STATUS_MODIFIED, Status.STATUS_ADDED, false); }
public void test199443_GlobalIgnoreFile () throws Exception { File f = new File(new File(workDir, "nbproject"), "file"); f.getParentFile().mkdirs(); f.createNewFile(); File ignoreFile = new File(workDir.getParentFile(), "globalignore"); write(ignoreFile, "nbproject"); Repository repo = getRepository(getLocalGitRepository()); StoredConfig cfg = repo.getConfig(); cfg.setString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_EXCLUDESFILE, ignoreFile.getAbsolutePath()); cfg.save(); GitClient client = getClient(workDir); assertEquals(Status.STATUS_IGNORED, client.getStatus(new File[] { f }, NULL_PROGRESS_MONITOR).get(f).getStatusIndexWC()); assertEquals(new File(workDir, Constants.GITIGNORE_FILENAME), client.unignore(new File[] { f }, NULL_PROGRESS_MONITOR)[0]); write(new File(workDir, Constants.GITIGNORE_FILENAME), "/nbproject/file"); assertEquals(new File(workDir, Constants.GITIGNORE_FILENAME), client.unignore(new File[] { f }, NULL_PROGRESS_MONITOR)[0]); assertEquals("!/nbproject/file", read(new File(workDir, Constants.GITIGNORE_FILENAME))); }
@Override public List<Remote> remoteList(String remoteName, boolean verbose) throws GitException { StoredConfig config = repository.getConfig(); Set<String> remoteNames = new HashSet<>(config.getSubsections(ConfigConstants.CONFIG_KEY_REMOTE)); if (remoteName != null && remoteNames.contains(remoteName)) { remoteNames.clear(); remoteNames.add(remoteName); } List<Remote> result = new ArrayList<>(remoteNames.size()); for (String remote : remoteNames) { try { List<URIish> uris = new RemoteConfig(config, remote).getURIs(); result.add( newDto(Remote.class) .withName(remote) .withUrl(uris.isEmpty() ? null : uris.get(0).toString())); } catch (URISyntaxException exception) { throw new GitException(exception.getMessage(), exception); } } return result; }
private static void logGcConfiguration( Project.NameKey projectName, Repository repo, boolean aggressive) { StringBuilder b = new StringBuilder(); Config cfg = repo.getConfig(); b.append("gc.aggressive=").append(aggressive).append("; "); b.append(formatConfigValues(cfg, ConfigConstants.CONFIG_GC_SECTION, null)); for (String subsection : cfg.getSubsections(ConfigConstants.CONFIG_GC_SECTION)) { b.append(formatConfigValues(cfg, ConfigConstants.CONFIG_GC_SECTION, subsection)); } if (b.length() == 0) { b.append("no set"); } logGcInfo(projectName, "gc config: " + b.toString()); logGcInfo(projectName, "pack config: " + (new PackConfig(repo)).toString()); }
private static void updateCoreIgnoreCaseSetting(@Nullable Git git) { if (SystemInfo.isFileSystemCaseSensitive) { return; } if (git == null) { LOG.info("jgit.Git is null, the command should have failed. Not updating the settings."); return; } StoredConfig config = git.getRepository().getConfig(); config.setString(ConfigConstants.CONFIG_CORE_SECTION, null, IGNORECASE_SETTING, Boolean.TRUE.toString()); try { config.save(); } catch (IOException e) { LOG.info("Couldn't save config for " + git.getRepository().getDirectory().getPath(), e); } }
public void test_clone_refspecs() throws Exception { List<RefSpec> refspecs = Lists.newArrayList( new RefSpec("+refs/heads/master:refs/remotes/origin/master"), new RefSpec("+refs/heads/1.4.x:refs/remotes/origin/1.4.x") ); w.git.clone_().url(localMirror()).refspecs(refspecs).repositoryName("origin").execute(); w.git.withRepository((Repository repo, VirtualChannel channel) -> { String[] fetchRefSpecs = repo.getConfig().getStringList(ConfigConstants.CONFIG_REMOTE_SECTION, Constants.DEFAULT_REMOTE_NAME, "fetch"); assertEquals("Expected 2 refspecs", 2, fetchRefSpecs.length); assertEquals("Incorrect refspec 1", "+refs/heads/master:refs/remotes/origin/master", fetchRefSpecs[0]); assertEquals("Incorrect refspec 2", "+refs/heads/1.4.x:refs/remotes/origin/1.4.x", fetchRefSpecs[1]); return null; }); Set<Branch> remoteBranches = w.git.getRemoteBranches(); assertBranchesExist(remoteBranches, "origin/master"); assertBranchesExist(remoteBranches, "origin/1.4.x"); assertEquals(2, remoteBranches.size()); }
public void setAutoSyncBranch (String branch, boolean autoSync) { boolean oldVal = getAutoSyncBranch(branch); if (oldVal != autoSync) { if (autoSync) { config.setBoolean(ConfigConstants.CONFIG_BRANCH_SECTION, branch, CONFIG_AUTO_SYNC, autoSync); } else { config.unset(ConfigConstants.CONFIG_BRANCH_SECTION, branch, CONFIG_AUTO_SYNC); if (config.getNames(ConfigConstants.CONFIG_BRANCH_SECTION, branch).isEmpty()) { config.unsetSection(ConfigConstants.CONFIG_BRANCH_SECTION, branch); } } save(); } }
private void setupRebaseFlag (Repository repository) throws IOException { Ref baseRef = repository.getRef(revision); if (baseRef != null && baseRef.getName().startsWith(Constants.R_REMOTES)) { StoredConfig config = repository.getConfig(); String autosetupRebase = config.getString(ConfigConstants.CONFIG_BRANCH_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOSETUPREBASE); boolean rebase = ConfigConstants.CONFIG_KEY_ALWAYS.equals(autosetupRebase) || ConfigConstants.CONFIG_KEY_REMOTE.equals(autosetupRebase); if (rebase && !config.getNames(ConfigConstants.CONFIG_BRANCH_SECTION, branchName).isEmpty()) { config.setBoolean(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_REBASE, rebase); config.save(); } } }
@Override protected void run () throws GitException { Repository repository = getRepository(); try { Ref ref = repository.getRef(trackedBranchName); if (ref == null) { throw new GitException(MessageFormat.format(Utils.getBundle(SetUpstreamBranchCommand.class) .getString("MSG_Error_UpdateTracking_InvalidReference"), trackedBranchName)); //NOI18N) } String remote = null; String branchName = ref.getName(); StoredConfig config = repository.getConfig(); if (branchName.startsWith(Constants.R_REMOTES)) { String[] elements = branchName.split("/", 4); remote = elements[2]; if (config.getSubsections(ConfigConstants.CONFIG_REMOTE_SECTION).contains(remote)) { branchName = Constants.R_HEADS + elements[3]; setupRebaseFlag(repository); } else { // remote not yet set remote = null; } } if (remote == null) { remote = "."; //NOI18N } config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, localBranchName, ConfigConstants.CONFIG_KEY_REMOTE, remote); config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, localBranchName, ConfigConstants.CONFIG_KEY_MERGE, branchName); config.save(); } catch (IOException ex) { throw new GitException(ex); } ListBranchCommand branchCmd = new ListBranchCommand(repository, getClassFactory(), false, new DelegatingGitProgressMonitor(monitor)); branchCmd.run(); Map<String, GitBranch> branches = branchCmd.getBranches(); branch = branches.get(localBranchName); }
private void setupRebaseFlag (Repository repository) throws IOException { StoredConfig config = repository.getConfig(); String autosetupRebase = config.getString(ConfigConstants.CONFIG_BRANCH_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOSETUPREBASE); boolean rebase = ConfigConstants.CONFIG_KEY_ALWAYS.equals(autosetupRebase) || ConfigConstants.CONFIG_KEY_REMOTE.equals(autosetupRebase); if (rebase) { config.setBoolean(ConfigConstants.CONFIG_BRANCH_SECTION, localBranchName, ConfigConstants.CONFIG_KEY_REBASE, rebase); } }
public void testCreateBranchWithRebase () throws Exception { final File otherWT = new File(workDir.getParentFile(), "repo2"); GitClient client = getClient(otherWT); client.init(NULL_PROGRESS_MONITOR); File f = new File(otherWT, "f"); write(f, "init"); client.add(new File[] { f }, NULL_PROGRESS_MONITOR); client.commit(new File[] { f }, "init commit", null, null, NULL_PROGRESS_MONITOR); client = getClient(workDir); client.setRemote(new GitRemoteConfig("origin", Arrays.asList(new String[] { otherWT.getAbsolutePath() }), Arrays.asList(new String[] { otherWT.getAbsolutePath() }), Arrays.asList(new String[] { "refs/heads/*:refs/remotes/origin/*" }), Arrays.asList(new String[] { "refs/remotes/origin/*:refs/heads/*" })), NULL_PROGRESS_MONITOR); client.fetch("origin", NULL_PROGRESS_MONITOR); StoredConfig config = repository.getConfig(); config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOSETUPREBASE, ConfigConstants.CONFIG_KEY_NEVER); config.save(); GitBranch b = client.createBranch(BRANCH_NAME, "origin/master", NULL_PROGRESS_MONITOR); assertFalse(repository.getConfig().getBoolean(ConfigConstants.CONFIG_BRANCH_SECTION, BRANCH_NAME, ConfigConstants.CONFIG_KEY_REBASE, false)); client.deleteBranch(BRANCH_NAME, true, NULL_PROGRESS_MONITOR); config = repository.getConfig(); config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOSETUPREBASE, ConfigConstants.CONFIG_KEY_REMOTE); config.save(); b = client.createBranch(BRANCH_NAME, "origin/master", NULL_PROGRESS_MONITOR); assertTrue(repository.getConfig().getBoolean(ConfigConstants.CONFIG_BRANCH_SECTION, BRANCH_NAME, ConfigConstants.CONFIG_KEY_REBASE, false)); }
public void testDeleteTrackedBranch () throws Exception { final File otherWT = new File(workDir.getParentFile(), "repo2"); GitClient client = getClient(otherWT); client.init(NULL_PROGRESS_MONITOR); File f = new File(otherWT, "f"); write(f, "init"); client.add(new File[] { f }, NULL_PROGRESS_MONITOR); client.commit(new File[] { f }, "init commit", null, null, NULL_PROGRESS_MONITOR); client = getClient(workDir); client.setRemote(new GitRemoteConfig("origin", Arrays.asList(new String[] { otherWT.getAbsolutePath() }), Arrays.asList(new String[] { otherWT.getAbsolutePath() }), Arrays.asList(new String[] { "refs/heads/*:refs/remotes/origin/*" }), Arrays.asList(new String[] { "refs/remotes/origin/*:refs/heads/*" })), NULL_PROGRESS_MONITOR); client.fetch("origin", NULL_PROGRESS_MONITOR); client.checkoutRevision("origin/master", true, NULL_PROGRESS_MONITOR); GitBranch b = client.createBranch(BRANCH_NAME, "origin/master", NULL_PROGRESS_MONITOR); Map<String, GitBranch> branches = client.getBranches(false, NULL_PROGRESS_MONITOR); assertEquals(2, branches.size()); assertNotNull(branches.get(BRANCH_NAME)); assertEquals(1, repository.getConfig().getSubsections(ConfigConstants.CONFIG_BRANCH_SECTION).size()); //delete tracked branch and test client.deleteBranch(BRANCH_NAME, false, NULL_PROGRESS_MONITOR); branches = client.getBranches(false, NULL_PROGRESS_MONITOR); assertEquals(1, branches.size()); assertNull(branches.get(BRANCH_NAME)); assertEquals(0, repository.getConfig().getSubsections(ConfigConstants.CONFIG_BRANCH_SECTION).size()); }
public void testBranchTracking () throws Exception { final File otherWT = new File(workDir.getParentFile(), "repo2"); GitClient client = getClient(otherWT); client.init(NULL_PROGRESS_MONITOR); File f = new File(otherWT, "f"); write(f, "init"); client.add(new File[] { f }, NULL_PROGRESS_MONITOR); client.commit(new File[] { f }, "init commit", null, null, NULL_PROGRESS_MONITOR); client = getClient(workDir); client.setRemote(new GitRemoteConfig("origin", Arrays.asList(otherWT.getAbsolutePath()), Arrays.asList(otherWT.getAbsolutePath()), Arrays.asList("+refs/heads/*:refs/remotes/origin/*"), Collections.<String>emptyList()), NULL_PROGRESS_MONITOR); client.fetch("origin", NULL_PROGRESS_MONITOR); GitBranch b = client.createBranch(Constants.MASTER, "origin/master", NULL_PROGRESS_MONITOR); assertEquals("origin/master", b.getTrackedBranch().getName()); assertTrue(b.getTrackedBranch().isRemote()); client.checkoutRevision(Constants.MASTER, true, NULL_PROGRESS_MONITOR); b = client.createBranch("nova1", Constants.MASTER, NULL_PROGRESS_MONITOR); assertNull(b.getTrackedBranch()); StoredConfig cfg = repository.getConfig(); cfg.setString(ConfigConstants.CONFIG_BRANCH_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOSETUPMERGE, "always"); cfg.save(); b = client.createBranch("nova2", Constants.MASTER, NULL_PROGRESS_MONITOR); assertEquals("master", b.getTrackedBranch().getName()); assertFalse(b.getTrackedBranch().isRemote()); // list branches Map<String, GitBranch> branches = client.getBranches(true, NULL_PROGRESS_MONITOR); b = branches.get(Constants.MASTER); assertEquals("origin/master", b.getTrackedBranch().getName()); assertTrue(b.getTrackedBranch().isRemote()); b = branches.get("origin/master"); assertNull(b.getTrackedBranch()); }
public void testBlameMixedLineEndings () throws Exception { File f = new File(workDir, "f"); String content = ""; for (int i = 0; i < 10000; ++i) { content += i + "\r\n"; } write(f, content); // lets turn autocrlf on StoredConfig cfg = repository.getConfig(); cfg.setString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOCRLF, "true"); cfg.save(); File[] files = new File[] { f }; GitClient client = getClient(workDir); client.add(files, NULL_PROGRESS_MONITOR); GitRevisionInfo info = client.commit(files, "commit", null, null, NULL_PROGRESS_MONITOR); content = content.replaceFirst("0", "01"); write(f, content); // it should be up to date again org.eclipse.jgit.api.BlameCommand cmd = new Git(repository).blame(); cmd.setFilePath("f"); BlameResult blameResult = cmd.call(); assertEquals(info.getRevision(), blameResult.getSourceCommit(1).getName()); GitBlameResult res = client.blame(f, null, NULL_PROGRESS_MONITOR); assertNull(res.getLineDetails(0)); assertLineDetails(f, 1, info.getRevision(), info.getAuthor(), info.getCommitter(), res.getLineDetails(1)); // without autocrlf it should all be modified cfg.setString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOCRLF, "false"); cfg.save(); res = client.blame(f, null, NULL_PROGRESS_MONITOR); assertNull(res.getLineDetails(1)); }
public void testIgnoreExecutable () throws Exception { if (isWindows()) { // no reason to test on win return; } File f = new File(workDir, "f"); write(f, "hi, i am executable"); f.setExecutable(true); File[] roots = { f }; add(roots); commit(roots); GitClient client = getClient(workDir); Map<File, GitStatus> statuses = client.getStatus(roots, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, f, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false); f.setExecutable(false); statuses = client.getStatus(roots, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, f, true, Status.STATUS_NORMAL, Status.STATUS_MODIFIED, Status.STATUS_MODIFIED, false); StoredConfig config = repository.getConfig(); config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_FILEMODE, false); config.save(); statuses = client.getStatus(roots, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, f, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false); config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_FILEMODE, true); config.save(); add(roots); statuses = client.getStatus(roots, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, f, true, Status.STATUS_MODIFIED, Status.STATUS_NORMAL, Status.STATUS_MODIFIED, false); config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_FILEMODE, false); config.save(); add(roots); statuses = client.getStatus(roots, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, f, true, Status.STATUS_MODIFIED, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false); }
private void assertConfig (FileBasedConfig config) throws Exception { config.load(); // filemode assertEquals(isWindows() ? "false" : "true", config.getString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_FILEMODE)); // bare assertEquals("false", config.getString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_BARE)); // autocrlf assertEquals(null, config.getString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOCRLF)); }
public void testMergeFFOnly () throws Exception { File f1 = new File(workDir, "file1"); File f2 = new File(workDir, "file2"); write(f1, "init"); write(f2, "init"); add(f1, f2); commit(f1, f2); GitClient client = getClient(workDir); client.createBranch(BRANCH_NAME, Constants.MASTER, NULL_PROGRESS_MONITOR); client.checkoutRevision(BRANCH_NAME, true, NULL_PROGRESS_MONITOR); write(f1, BRANCH_NAME); add(f1); client.commit(new File[] { f1 }, "change on branch", null, null, NULL_PROGRESS_MONITOR); client.checkoutRevision(Constants.MASTER, true, NULL_PROGRESS_MONITOR); write(f2, "another change"); add(f2); client.commit(new File[] { f2 }, "change on master", null, null, NULL_PROGRESS_MONITOR); GitMergeResult result = client.merge(BRANCH_NAME, GitRepository.FastForwardOption.FAST_FORWARD_ONLY, NULL_PROGRESS_MONITOR); // no merge commits allowed => FAIL assertEquals(MergeStatus.ABORTED, result.getMergeStatus()); // test also config files assertEquals(GitRepository.FastForwardOption.FAST_FORWARD, GitRepository.getInstance(workDir).getDefaultFastForwardOption()); StoredConfig cfg = repo.getConfig(); cfg.setEnum(ConfigConstants.CONFIG_KEY_MERGE, null, ConfigConstants.CONFIG_KEY_FF, org.eclipse.jgit.api.MergeCommand.FastForwardMode.Merge.ONLY); cfg.save(); assertEquals(GitRepository.FastForwardOption.FAST_FORWARD_ONLY, GitRepository.getInstance(workDir).getDefaultFastForwardOption()); result = client.merge(BRANCH_NAME, NULL_PROGRESS_MONITOR); // no merge commits allowed => FAIL assertEquals(MergeStatus.ABORTED, result.getMergeStatus()); result = client.merge(BRANCH_NAME, GitRepository.FastForwardOption.FAST_FORWARD, NULL_PROGRESS_MONITOR); // merge commits allowed => OK assertEquals(MergeStatus.MERGED, result.getMergeStatus()); }
public void testAddKeepExecutableInIndex () throws Exception { if (isWindows()) { // no reason to test on windows return; } File f = new File(workDir, "f"); write(f, "hi, i am executable"); f.setExecutable(true); File[] roots = { f }; GitClient client = getClient(workDir); add(roots); Map<File, GitStatus> statuses = client.getStatus(roots, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, f, true, Status.STATUS_ADDED, Status.STATUS_NORMAL, Status.STATUS_ADDED, false); StoredConfig config = repository.getConfig(); config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_FILEMODE, false); config.save(); // add should not overwrite executable bit in index f.setExecutable(false); add(roots); statuses = client.getStatus(roots, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, f, true, Status.STATUS_ADDED, Status.STATUS_NORMAL, Status.STATUS_ADDED, false); // index should differ from wt config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_FILEMODE, true); config.save(); statuses = client.getStatus(roots, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, f, true, Status.STATUS_ADDED, Status.STATUS_MODIFIED, Status.STATUS_ADDED, false); }
public void testUpdateIndexIgnoreExecutable () throws Exception { if (isWindows()) { // no reason to test on windows return; } File f = new File(workDir, "f"); write(f, "hi, i am not executable"); File[] roots = { f }; add(roots); commit(roots); f.setExecutable(true); GitClient client = getClient(workDir); StoredConfig config = repository.getConfig(); config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_FILEMODE, false); config.save(); write(f, "hi, i am executable"); // add should not set executable bit in index add(roots); Map<File, GitStatus> statuses = client.getStatus(roots, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, f, true, Status.STATUS_MODIFIED, Status.STATUS_NORMAL, Status.STATUS_MODIFIED, false); // index should differ from wt config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_FILEMODE, true); config.save(); statuses = client.getStatus(roots, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, f, true, Status.STATUS_MODIFIED, Status.STATUS_MODIFIED, Status.STATUS_MODIFIED, false); }
@Override protected void setup() { gitDir = BootstrapUtils.createTempDir(); try { git = org.eclipse.jgit.api.Git.init().setBare(false).setDirectory(gitDir).call(); } catch (IllegalStateException | GitAPIException e) { throw new RuntimeException(e); } git.getRepository().getConfig().setEnum(ConfigConstants.CONFIG_DIFF_SECTION, null, ConfigConstants.CONFIG_KEY_ALGORITHM, SupportedAlgorithm.HISTOGRAM); Mockito.when(AppLoader.getInstance(GitConfig.class)).thenReturn(new GitConfig() { private static final long serialVersionUID = 1L; @Override public String getExecutable() { return "git"; } }); Assert.assertTrue(GitCommand.checkError("git") == null); }
private String getUrl(RepositoryMapping mapping, String branch) { StoredConfig config = mapping.getRepository().getConfig(); String remote = config.getString(ConfigConstants.CONFIG_BRANCH_SECTION, branch, ConfigConstants.CONFIG_KEY_REMOTE); String url = config.getString(ConfigConstants.CONFIG_REMOTE_SECTION, remote, ConfigConstants.CONFIG_KEY_URL); return url; }
@Override public void remoteDelete(String name) throws GitException { StoredConfig config = repository.getConfig(); Set<String> remoteNames = config.getSubsections(ConfigConstants.CONFIG_KEY_REMOTE); if (!remoteNames.contains(name)) { throw new GitException("error: Could not remove config section 'remote." + name + "'"); } config.unsetSection(ConfigConstants.CONFIG_REMOTE_SECTION, name); Set<String> branches = config.getSubsections(ConfigConstants.CONFIG_BRANCH_SECTION); for (String branch : branches) { String r = config.getString( ConfigConstants.CONFIG_BRANCH_SECTION, branch, ConfigConstants.CONFIG_KEY_REMOTE); if (name.equals(r)) { config.unset( ConfigConstants.CONFIG_BRANCH_SECTION, branch, ConfigConstants.CONFIG_KEY_REMOTE); config.unset( ConfigConstants.CONFIG_BRANCH_SECTION, branch, ConfigConstants.CONFIG_KEY_MERGE); List<Branch> remoteBranches = branchList(LIST_REMOTE); for (Branch remoteBranch : remoteBranches) { if (remoteBranch.getDisplayName().startsWith(name)) { branchDelete(remoteBranch.getName(), true); } } } } try { config.save(); } catch (IOException exception) { throw new GitException(exception.getMessage(), exception); } }
public static void addRemote(final Repository repo, final String remote, final String url) { try { // Add the new remote { final RemoteAddCommand remoteAdd = new Git(repo).remoteAdd(); remoteAdd.setName(remote); remoteAdd.setUri(new URIish(url)); remoteAdd.call(); } // Set up tracking { StoredConfig config = repo.getConfig(); config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, "master", "remote", remote); config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, "master", "merge", "refs/heads/master"); config.save(); } } catch (IOException | URISyntaxException | GitAPIException e) { throw new RuntimeException("Failed to issue git remote add", e); } }
public void test_clone_refspec() throws Exception { w.git.clone_().url(localMirror()).repositoryName("origin").execute(); final WorkingArea w2 = new WorkingArea(); w2.launchCommand("git", "clone", localMirror(), "./"); w2.git.withRepository((final Repository realRepo, VirtualChannel channel) -> w.git.withRepository((final Repository implRepo, VirtualChannel channel1) -> { final String realRefspec = realRepo.getConfig().getString(ConfigConstants.CONFIG_REMOTE_SECTION, Constants.DEFAULT_REMOTE_NAME, "fetch"); final String implRefspec = implRepo.getConfig().getString(ConfigConstants.CONFIG_REMOTE_SECTION, Constants.DEFAULT_REMOTE_NAME, "fetch"); assertEquals("Refspec not as git-clone", realRefspec, implRefspec); return null; })); }
public boolean getAutoSyncBranch (String branch) { return config.getBoolean(ConfigConstants.CONFIG_BRANCH_SECTION, branch, CONFIG_AUTO_SYNC, false); }
private void mergeConflicts (List<String> conflicts, DirCache cache) throws GitException { DirCacheBuilder builder = cache.builder(); DirCacheBuildIterator dci = new DirCacheBuildIterator(builder); TreeWalk walk = new TreeWalk(getRepository()); ObjectDatabase od = null; DiffAlgorithm.SupportedAlgorithm diffAlg = getRepository().getConfig().getEnum( ConfigConstants.CONFIG_DIFF_SECTION, null, ConfigConstants.CONFIG_KEY_ALGORITHM, DiffAlgorithm.SupportedAlgorithm.HISTOGRAM); MergeAlgorithm merger = new MergeAlgorithm(DiffAlgorithm.getAlgorithm(diffAlg)); try { od = getRepository().getObjectDatabase(); walk.addTree(dci); walk.setFilter(PathFilterGroup.create(Utils.getPathFilters(conflicts))); String lastPath = null; DirCacheEntry[] entries = new DirCacheEntry[3]; walk.setRecursive(true); while (walk.next()) { DirCacheEntry e = walk.getTree(0, DirCacheIterator.class).getDirCacheEntry(); String path = e.getPathString(); if (lastPath != null && !lastPath.equals(path)) { resolveEntries(merger, lastPath, entries, od, builder); } if (e.getStage() == 0) { DirCacheIterator c = walk.getTree(0, DirCacheIterator.class); builder.add(c.getDirCacheEntry()); } else { entries[e.getStage() - 1] = e; lastPath = path; } } resolveEntries(merger, lastPath, entries, od, builder); builder.commit(); } catch (IOException ex) { throw new GitException(ex); } finally { walk.release(); if (od != null) { od.close(); } } }
public static boolean checkExecutable (Repository repository) { return repository.getConfig().getBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_FILEMODE, true); }
public void testRemoteTracking () throws Exception { GitClient client = getClient(workDir); File f = new File(workDir, "f"); add(f); client.commit(new File[] { f }, "init commit", null, null, NULL_PROGRESS_MONITOR); // push to remote String remoteUri = getRemoteRepository().getWorkTree().toURI().toString(); client.setRemote(new GitRemoteConfig("origin", Arrays.asList(remoteUri), Collections.<String>emptyList(), Arrays.asList("+refs/heads/*:refs/remotes/origin/*"), Collections.<String>emptyList()), NULL_PROGRESS_MONITOR); client.push("origin", Arrays.asList("refs/heads/master:refs/heads/master"), Arrays.asList("+refs/heads/master:refs/remotes/origin/master"), NULL_PROGRESS_MONITOR); Map<String, GitBranch> branches = client.getBranches(true, NULL_PROGRESS_MONITOR); assertTrue(branches.containsKey("origin/master")); assertNull(branches.get("master").getTrackedBranch()); StoredConfig config = repository.getConfig(); config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOSETUPREBASE, ConfigConstants.CONFIG_KEY_NEVER); config.save(); // set tracking GitBranch b = client.setUpstreamBranch("master", "origin/master", NULL_PROGRESS_MONITOR); assertEquals("origin/master", b.getTrackedBranch().getName()); config = repository.getConfig(); assertEquals("origin", config.getString(ConfigConstants.CONFIG_BRANCH_SECTION, "master", ConfigConstants.CONFIG_KEY_REMOTE)); assertEquals("refs/heads/master", config.getString(ConfigConstants.CONFIG_BRANCH_SECTION, "master", ConfigConstants.CONFIG_KEY_MERGE)); assertFalse(config.getBoolean(ConfigConstants.CONFIG_BRANCH_SECTION, "master", ConfigConstants.CONFIG_KEY_REBASE, false)); // change autosetuprebase config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOSETUPREBASE, ConfigConstants.CONFIG_KEY_REMOTE); config.save(); // set tracking b = client.setUpstreamBranch("master", "origin/master", NULL_PROGRESS_MONITOR); assertEquals("origin/master", b.getTrackedBranch().getName()); config = repository.getConfig(); assertEquals("origin", config.getString(ConfigConstants.CONFIG_BRANCH_SECTION, "master", ConfigConstants.CONFIG_KEY_REMOTE)); assertEquals("refs/heads/master", config.getString(ConfigConstants.CONFIG_BRANCH_SECTION, "master", ConfigConstants.CONFIG_KEY_MERGE)); assertTrue(config.getBoolean(ConfigConstants.CONFIG_BRANCH_SECTION, "master", ConfigConstants.CONFIG_KEY_REBASE, false)); }
public void testLineEndingsWindows () throws Exception { if (!isWindows()) { return; } // lets turn autocrlf on Thread.sleep(1100); StoredConfig cfg = repository.getConfig(); cfg.setString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOCRLF, "true"); cfg.save(); File f = new File(workDir, "f"); write(f, "a\r\nb\r\n"); File[] roots = new File[] { f }; GitClient client = getClient(workDir); runExternally(workDir, Arrays.asList("git.cmd", "add", "f")); List<String> res = runExternally(workDir, Arrays.asList("git.cmd", "status", "-s")); assertEquals(Arrays.asList("A f"), res); DirCacheEntry e1 = repository.readDirCache().getEntry("f"); runExternally(workDir, Arrays.asList("git.cmd", "commit", "-m", "hello")); write(f, "a\r\nb\r\nc\r\n"); res = runExternally(workDir, Arrays.asList("git.cmd", "status", "-s")); assertEquals(Arrays.asList(" M f"), res); runExternally(workDir, Arrays.asList("git.cmd", "add", "f")); res = runExternally(workDir, Arrays.asList("git.cmd", "status", "-s")); assertEquals(Arrays.asList("M f"), res); assertStatus(client.getStatus(roots, NULL_PROGRESS_MONITOR), workDir, f, true, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_MODIFIED, false); client.checkout(roots, "HEAD", true, NULL_PROGRESS_MONITOR); assertStatus(client.getStatus(roots, NULL_PROGRESS_MONITOR), workDir, f, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); assertEquals(e1.getObjectId(), repository.readDirCache().getEntry("f").getObjectId()); res = runExternally(workDir, Arrays.asList("git.cmd", "status", "-s")); assertEquals(0, res.size()); write(f, "a\r\nb\r\nc\r\n"); res = runExternally(workDir, Arrays.asList("git.cmd", "status", "-s")); assertEquals(Arrays.asList(" M f"), res); assertStatus(client.getStatus(roots, NULL_PROGRESS_MONITOR), workDir, f, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_MODIFIED, false); client.checkout(roots, null, true, NULL_PROGRESS_MONITOR); assertStatus(client.getStatus(roots, NULL_PROGRESS_MONITOR), workDir, f, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); assertEquals(e1.getObjectId(), repository.readDirCache().getEntry("f").getObjectId()); res = runExternally(workDir, Arrays.asList("git.cmd", "status", "-s")); assertEquals(0, res.size()); }
public void testLineEndingsWindows () throws Exception { if (!isWindows()) { return; } // lets turn autocrlf on Thread.sleep(1100); StoredConfig cfg = repository.getConfig(); cfg.setString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOCRLF, "true"); cfg.save(); File f = new File(workDir, "f"); write(f, "a\r\nb\r\n"); File[] roots = new File[] { f }; GitClient client = getClient(workDir); runExternally(workDir, Arrays.asList("git.cmd", "add", "f")); List<String> res = runExternally(workDir, Arrays.asList("git.cmd", "status", "-s")); assertEquals(Arrays.asList("A f"), res); DirCacheEntry e1 = repository.readDirCache().getEntry("f"); runExternally(workDir, Arrays.asList("git.cmd", "commit", "-m", "hello")); write(f, "a\r\nb\r\nc\r\n"); res = runExternally(workDir, Arrays.asList("git.cmd", "status", "-s")); assertEquals(Arrays.asList(" M f"), res); runExternally(workDir, Arrays.asList("git.cmd", "add", "f")); res = runExternally(workDir, Arrays.asList("git.cmd", "status", "-s")); assertEquals(Arrays.asList("M f"), res); assertStatus(client.getStatus(roots, NULL_PROGRESS_MONITOR), workDir, f, true, Status.STATUS_MODIFIED, Status.STATUS_NORMAL, Status.STATUS_MODIFIED, false); client.reset(roots, "HEAD", true, NULL_PROGRESS_MONITOR); assertStatus(client.getStatus(roots, NULL_PROGRESS_MONITOR), workDir, f, true, Status.STATUS_NORMAL, Status.STATUS_MODIFIED, Status.STATUS_MODIFIED, false); assertEquals(e1.getObjectId(), repository.readDirCache().getEntry("f").getObjectId()); res = runExternally(workDir, Arrays.asList("git.cmd", "status", "-s")); assertEquals(Arrays.asList(" M f"), res); runExternally(workDir, Arrays.asList("git.cmd", "add", "f")); res = runExternally(workDir, Arrays.asList("git.cmd", "status", "-s")); assertEquals(Arrays.asList("M f"), res); assertStatus(client.getStatus(roots, NULL_PROGRESS_MONITOR), workDir, f, true, Status.STATUS_MODIFIED, Status.STATUS_NORMAL, Status.STATUS_MODIFIED, false); client.reset("HEAD", ResetType.HARD, NULL_PROGRESS_MONITOR); assertStatus(client.getStatus(roots, NULL_PROGRESS_MONITOR), workDir, f, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false); assertEquals(e1.getObjectId(), repository.readDirCache().getEntry("f").getObjectId()); res = runExternally(workDir, Arrays.asList("git.cmd", "status", "-s")); assertEquals(0, res.size()); }
public void testAddMixedLineEndings () throws Exception { File f = new File(workDir, "f"); String content = ""; for (int i = 0; i < 10000; ++i) { content += i + "\r\n"; } write(f, content); File[] files = new File[] { f }; GitClient client = getClient(workDir); client.add(files, NULL_PROGRESS_MONITOR); client.commit(files, "commit", null, null, NULL_PROGRESS_MONITOR); Map<File, GitStatus> statuses = client.getStatus(files, NULL_PROGRESS_MONITOR); assertEquals(1, statuses.size()); assertStatus(statuses, workDir, f, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false); // lets turn autocrlf on StoredConfig cfg = repository.getConfig(); cfg.setString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOCRLF, "true"); cfg.save(); // when this starts failing, remove the work around ObjectInserter inserter = repository.newObjectInserter(); TreeWalk treeWalk = new TreeWalk(repository); treeWalk.setFilter(PathFilterGroup.createFromStrings("f")); treeWalk.setRecursive(true); treeWalk.reset(); treeWalk.addTree(new FileTreeIterator(repository)); while (treeWalk.next()) { String path = treeWalk.getPathString(); assertEquals("f", path); WorkingTreeIterator fit = treeWalk.getTree(0, WorkingTreeIterator.class); InputStream in = fit.openEntryStream(); try { inserter.insert(Constants.OBJ_BLOB, fit.getEntryLength(), in); fail("this should fail, remove the work around"); } catch (EOFException ex) { assertEquals("Input did not match supplied length. 10000 bytes are missing.", ex.getMessage()); } finally { in.close(); inserter.release(); } break; } // no err should occur write(f, content + "hello"); statuses = client.getStatus(files, NULL_PROGRESS_MONITOR); assertEquals(1, statuses.size()); assertStatus(statuses, workDir, f, true, Status.STATUS_NORMAL, Status.STATUS_MODIFIED, Status.STATUS_MODIFIED, false); client.add(files, NULL_PROGRESS_MONITOR); statuses = client.getStatus(files, NULL_PROGRESS_MONITOR); assertEquals(1, statuses.size()); assertStatus(statuses, workDir, f, true, Status.STATUS_MODIFIED, Status.STATUS_NORMAL, Status.STATUS_MODIFIED, false); client.commit(files, "message", null, null, NULL_PROGRESS_MONITOR); statuses = client.getStatus(files, NULL_PROGRESS_MONITOR); assertEquals(1, statuses.size()); assertStatus(statuses, workDir, f, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false); }
public void testLineEndingsWindows () throws Exception { if (!isWindows()) { return; } // lets turn autocrlf on StoredConfig cfg = repository.getConfig(); cfg.setString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOCRLF, "true"); cfg.save(); File f = new File(workDir, "f"); write(f, "a\r\nb\r\n"); File[] roots = new File[] { f }; GitClient client = getClient(workDir); runExternally(workDir, Arrays.asList("git.cmd", "add", "f")); DirCacheEntry e1 = repository.readDirCache().getEntry("f"); client.add(roots, NULL_PROGRESS_MONITOR); DirCacheEntry e2 = repository.readDirCache().getEntry("f"); assertStatus(client.getStatus(roots, NULL_PROGRESS_MONITOR), workDir, f, true, Status.STATUS_ADDED, Status.STATUS_NORMAL, Status.STATUS_ADDED, false); List<String> res = runExternally(workDir, Arrays.asList("git.cmd", "status", "-s")); assertEquals(Arrays.asList("A f"), res); assertEquals(e1.getFileMode(), e2.getFileMode()); assertEquals(e1.getPathString(), e2.getPathString()); assertEquals(e1.getRawMode(), e2.getRawMode()); assertEquals(e1.getStage(), e2.getStage()); assertEquals(e1.getLength(), e2.getLength()); assertEquals(e1.getObjectId(), e2.getObjectId()); write(f, "a\nb\n"); res = runExternally(workDir, Arrays.asList("git.cmd", "status", "-s")); assertEquals(Arrays.asList("AM f"), res); assertStatus(client.getStatus(roots, NULL_PROGRESS_MONITOR), workDir, f, true, Status.STATUS_ADDED, Status.STATUS_MODIFIED, Status.STATUS_ADDED, false); res = runExternally(workDir, Arrays.asList("git.cmd", "commit", "-m", "gugu")); res = runExternally(workDir, Arrays.asList("git.cmd", "checkout", "--", "f")); RevCommit commit = Utils.findCommit(repository, "HEAD"); TreeWalk walk = new TreeWalk(repository); walk.reset(); walk.addTree(commit.getTree()); walk.setFilter(PathFilter.create("f")); walk.setRecursive(true); walk.next(); assertEquals("f", walk.getPathString()); ObjectLoader loader = repository.getObjectDatabase().open(walk.getObjectId(0)); assertEquals(4, loader.getSize()); assertEquals("a\nb\n", new String(loader.getBytes())); assertEquals(e1.getObjectId(), walk.getObjectId(0)); res = runExternally(workDir, Arrays.asList("git.cmd", "status", "-s")); assertEquals(0, res.size()); assertStatus(client.getStatus(roots, NULL_PROGRESS_MONITOR), workDir, f, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false); }