Java源码示例:org.eclipse.jgit.lib.ConfigConstants
示例1
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();
}
}
}
示例2
@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);
}
}
示例3
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);
}
}
示例4
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());
}
示例5
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)));
}
示例6
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));
}
示例7
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));
}
示例8
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()));
}
示例9
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);
}
示例10
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)));
}
示例11
public static void doConfigureClone(Git git, String user, String gitUserName, String gitUserMail) throws IOException, CoreException, JSONException {
StoredConfig config = git.getRepository().getConfig();
if (gitUserName == null && gitUserMail == null) {
JSONObject gitUserConfig = getUserGitConfig(user);
if (gitUserConfig != null) {
gitUserName = gitUserConfig.getString("GitName"); //$NON-NLS-1$
gitUserMail = gitUserConfig.getString("GitMail"); //$NON-NLS-1$
}
}
if (gitUserName != null)
config.setString(ConfigConstants.CONFIG_USER_SECTION, null, ConfigConstants.CONFIG_KEY_NAME, gitUserName);
if (gitUserMail != null)
config.setString(ConfigConstants.CONFIG_USER_SECTION, null, ConfigConstants.CONFIG_KEY_EMAIL, gitUserMail);
config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_FILEMODE, false);
config.save();
}
示例12
private boolean handleDelete(HttpServletRequest request, HttpServletResponse response, String path) throws CoreException, IOException, URISyntaxException,
JSONException, ServletException {
Path p = new Path(path);
if (p.segment(1).equals("file")) { //$NON-NLS-1$
// expected path: /gitapi/remote/{remote}/file/{path}
String remoteName = p.segment(0);
File gitDir = GitUtils.getGitDir(p.removeFirstSegments(1));
Repository db = null;
try {
db = FileRepositoryBuilder.create(gitDir);
StoredConfig config = db.getConfig();
config.unsetSection(ConfigConstants.CONFIG_REMOTE_SECTION, remoteName);
config.save();
// TODO: handle result
return true;
} finally {
if (db != null) {
db.close();
}
}
}
return false;
}
示例13
@PropertyDescription(name = GitConstants.KEY_REMOTE)
private JSONArray getRemotes() throws URISyntaxException, JSONException, IOException, CoreException {
String branchName = Repository.shortenRefName(ref.getName());
String remoteName = getConfig().getString(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_REMOTE);
List<RemoteConfig> remoteConfigs = RemoteConfig.getAllRemoteConfigs(getConfig());
ArrayList<JSONObject> remotes = new ArrayList<JSONObject>();
for (RemoteConfig remoteConfig : remoteConfigs) {
if (!remoteConfig.getFetchRefSpecs().isEmpty()) {
Remote r = new Remote(cloneLocation, db, remoteConfig.getName());
r.setNewBranch(branchName);
// Ensure that the remote tracking branch is the first in the list.
// Insert at the beginning of the list as well when the remote tracking branch is not set but the branch has been pushed to the remote
if (remoteConfig.getName().equals(remoteName) || (remoteName == null && db.resolve(Constants.R_REMOTES + remoteConfig.getName() + "/" + branchName) != null)) {
remotes.add(0, r.toJSON());
} else {
remotes.add(r.toJSON());
}
}
}
JSONArray result = new JSONArray();
for (JSONObject remote : remotes) {
result.put(remote);
}
return result;
}
示例14
private Ref findRef() {
try {
Set<String> configNames = getConfig().getSubsections(ConfigConstants.CONFIG_REMOTE_SECTION);
for (String configName : configNames) {
if (configName.equals(remote.getName())) {
final String fullName = getName(true, false);
Ref ref = db.getRefDatabase().getRef(fullName);
if (ref != null && !ref.isSymbolic()) {
return ref;
}
}
}
} catch (IOException e) {
// ignore, return null
}
return null;
}
示例15
@Test
public void testGetCloneAndPull() throws Exception {
// see bug 339254
createWorkspace(SimpleMetaStore.DEFAULT_WORKSPACE_NAME);
String workspaceId = getWorkspaceId(workspaceLocation);
JSONObject project = createProjectOrLink(workspaceLocation, getMethodName().concat("Project"), null);
String contentLocation = clone(workspaceId, project).getString(ProtocolConstants.KEY_CONTENT_LOCATION);
JSONArray clonesArray = listClones(workspaceId, null);
assertEquals(1, clonesArray.length());
Repository r = getRepositoryForContentLocation(contentLocation);
// overwrite user settings, do not rebase when pulling, see bug 372489
StoredConfig cfg = r.getConfig();
cfg.setBoolean(ConfigConstants.CONFIG_BRANCH_SECTION, Constants.MASTER, ConfigConstants.CONFIG_KEY_REBASE, false);
cfg.save();
// TODO: replace with RESTful API when ready, see bug 339114
Git git = Git.wrap(r);
PullResult pullResult = git.pull().call();
assertEquals(pullResult.getMergeResult().getMergeStatus(), MergeStatus.ALREADY_UP_TO_DATE);
assertEquals(RepositoryState.SAFE, git.getRepository().getRepositoryState());
}
示例16
@Test
public void test_clone_refspecs() throws Exception {
List<RefSpec> refspecs = Arrays.asList(
new RefSpec("+refs/heads/master:refs/remotes/origin/master"),
new RefSpec("+refs/heads/1.4.x:refs/remotes/origin/1.4.x")
);
testGitClient.clone_().url(workspace.localMirror()).refspecs(refspecs).repositoryName("origin").execute();
testGitClient.withRepository((Repository workRepo, VirtualChannel channel) -> {
String[] fetchRefSpecs = workRepo.getConfig().getStringList(ConfigConstants.CONFIG_REMOTE_SECTION, Constants.DEFAULT_REMOTE_NAME, "fetch");
assertThat(fetchRefSpecs.length, is(2));
assertThat(fetchRefSpecs[0], is("+refs/heads/master:refs/remotes/origin/master"));
assertThat(fetchRefSpecs[1], is("+refs/heads/1.4.x:refs/remotes/origin/1.4.x"));
return null;
});
Set<Branch> remoteBranches = testGitClient.getRemoteBranches();
assertBranchesExist(remoteBranches, "origin/master");
assertBranchesExist(remoteBranches, "origin/1.4.x");
assertThat(remoteBranches.size(), is(2));
}
示例17
/**
* {@inheritDoc}
*/
@Override
public String getText(Object element) {
if (element instanceof Path) {
try (final Git repo = Git.open(((Path) element).toFile())) {
return repo.getRepository().getConfig().getString(ConfigConstants.CONFIG_REMOTE_SECTION, "origin", //$NON-NLS-1$
ConfigConstants.CONFIG_KEY_URL);
} catch (IOException e) {
Logger.getLogger(GitRepositoriesPreferencePage.class.getName()).log(Level.SEVERE, e.getMessage(),
e);
}
}
return super.getText(element);
}
示例18
private static FastForwardMode getFastForwardMode(Config config,
String[] mergeOptions) {
for (String option : mergeOptions) {
for (FastForwardMode mode : FastForwardMode.values())
if (mode.matchConfigValue(option))
return mode;
}
FastForwardMode ffmode = FastForwardMode.valueOf(config.getEnum(
ConfigConstants.CONFIG_KEY_MERGE, null,
ConfigConstants.CONFIG_KEY_FF, FastForwardMode.Merge.TRUE));
return ffmode;
}
示例19
private static String[] getMergeOptions(String branch, Config config) {
String mergeOptions = config.getString(
ConfigConstants.CONFIG_BRANCH_SECTION, branch,
ConfigConstants.CONFIG_KEY_MERGEOPTIONS);
if (mergeOptions != null) {
return mergeOptions.split("\\s"); //$NON-NLS-1$
}
return new String[0];
}
示例20
@Override
protected void setup() {
gitDir = FileUtils.createTempDir();
try {
git = 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";
}
});
String gitError = GitCommand.checkError("git");
Assert.assertTrue(gitError, gitError == null);
}
示例21
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();
}
}
示例22
private void setupRebaseFlag (Repository repository) throws IOException {
Ref baseRef = repository.findRef(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();
}
}
}
示例23
private void mergeConflicts (List<String> conflicts, DirCache cache) throws GitException {
DirCacheBuilder builder = cache.builder();
DirCacheBuildIterator dci = new DirCacheBuildIterator(builder);
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 (TreeWalk walk = new TreeWalk(getRepository());) {
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 {
if (od != null) {
od.close();
}
}
}
示例24
@Override
protected void run () throws GitException {
Repository repository = getRepository();
try {
Ref ref = repository.findRef(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);
}
示例25
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);
}
}
示例26
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));
}
示例27
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());
}
示例28
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());
}
示例29
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));
}
示例30
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);
}