项目:incubator-netbeans
文件:JGitUtils.java
public static boolean isUserSetup (File root) {
Repository repository = getRepository(root);
boolean userExists = true;
if (repository != null) {
try {
StoredConfig config = repository.getConfig();
String name = config.getString("user",null,"name"); //NOI18N
String email = config.getString("user","email"); //NOI18N
if (name == null || name.isEmpty() || email == null || email.isEmpty()) {
userExists = false;
}
} finally {
repository.close();
}
}
return userExists;
}
项目:incubator-netbeans
文件:JGitUtils.java
public static void persistUser (File root,GitUser author) throws GitException {
Repository repository = getRepository(root);
if (repository != null) {
try {
StoredConfig config = repository.getConfig();
config.setString("user","name",author.getName()); //NOI18N
config.setString("user","email",author.getEmailAddress()); //NOI18N
try {
config.save();
FileUtil.refreshFor(new File(GitUtils.getGitFolderForRoot(root),"config"));
} catch (IOException ex) {
throw new GitException(ex);
}
} finally {
repository.close();
}
}
}
项目:incubator-netbeans
文件:RemoveRemoteCommand.java
@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,ConfigConstants.CONfig_KEY_REMOTE);
config.unset(ConfigConstants.CONfig_BRANCH_SECTION,ConfigConstants.CONfig_KEY_MERGE);
}
}
try {
config.save();
} catch (IOException ex) {
throw new GitException(ex);
}
}
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,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,NULL_PROGRESS_MONITOR).get(f).getStatusIndexWC());
assertEquals(dotGitIgnoreFile,NULL_PROGRESS_MONITOR)[0]);
assertEquals(Status.STATUS_IGnorED,NULL_PROGRESS_MONITOR).get(f).getStatusIndexWC());
}
public void test199443_GlobalIgnoreFileOverwrite () throws Exception {
File f = new File(new File(workdir,"globalignore");
Repository repo = getRepository(getLocalgitRepository());
StoredConfig cfg = repo.getConfig();
cfg.setString(ConfigConstants.CONfig_CORE_SECTION,ignoreFile.getAbsolutePath());
cfg.save();
write(ignoreFile,"!nbproject");
GitClient client = getClient(workdir);
assertEquals(new File(workdir,Constants.GITIGnorE_FILENAME),NULL_PROGRESS_MONITOR)[0]);
assertEquals("/nbproject/file",read(new File(workdir,Constants.GITIGnorE_FILENAME)));
}
项目:incubator-netbeans
文件:RemotesTest.java
public void testAddRemote () throws Exception {
StoredConfig config = repository.getConfig();
assertEquals(0,config.getSubsections("remote").size());
GitClient client = getClient(workdir);
GitRemoteConfig remoteConfig = new GitRemoteConfig("origin",Arrays.asList(new File(workdir.getParentFile(),"repo2").toURI().toString()),Arrays.asList("+refs/heads/*:refs/remotes/origin/*"),Arrays.asList("refs/remotes/origin/*:+refs/heads/*"));
client.setRemote(remoteConfig,NULL_PROGRESS_MONITOR);
config.load();
RemoteConfig cfg = new RemoteConfig(config,"origin");
assertEquals(Arrays.asList(new URIish(new File(workdir.getParentFile(),"repo2").toURI().toString())),cfg.getURIs());
assertEquals(Arrays.asList(new URIish(new File(workdir.getParentFile(),cfg.getPushURIs());
assertEquals(Arrays.asList(new RefSpec("+refs/heads/*:refs/remotes/origin/*")),cfg.getFetchRefSpecs());
assertEquals(Arrays.asList(new RefSpec("refs/remotes/origin/*:+refs/heads/*")),cfg.getPushRefSpecs());
}
项目:incubator-netbeans
文件:MergeTest.java
public void testMergeBranchNoHeadYet_196837 () throws Exception {
StoredConfig cfg = getRemoteRepository().getConfig();
cfg.setBoolean(ConfigConstants.CONfig_CORE_SECTION,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_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()));
}
项目:incubator-netbeans
文件:AddTest.java
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,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,false);
// index should differ from wt
config.setBoolean(ConfigConstants.CONfig_CORE_SECTION,true);
config.save();
statuses = client.getStatus(roots,Status.STATUS_MODIFIED,false);
}
public void test199443_GlobalIgnoreFile () throws Exception {
File f = new File(new File(workdir,"nbproject");
Repository repo = getRepository(getLocalgitRepository());
StoredConfig cfg = repo.getConfig();
cfg.setString(ConfigConstants.CONfig_CORE_SECTION,NULL_PROGRESS_MONITOR).get(f).getStatusIndexWC());
assertEquals(new File(workdir,client.unignore(new File[] { f },NULL_PROGRESS_MONITOR)[0]);
write(new File(workdir,"/nbproject/file");
assertEquals(new File(workdir,NULL_PROGRESS_MONITOR)[0]);
assertEquals("!/nbproject/file",Constants.GITIGnorE_FILENAME)));
}
项目:oxygen-git-plugin
文件:AddRemoteDialog.java
/**
* Adds the remote as origin to the repository
*/
@Override
protected void doOK() {
super.doOK();
StoredConfig config;
try {
config = Gitaccess.getInstance().getRepository().getConfig();
RemoteConfig remoteConfig = new RemoteConfig(config,"origin");
URIish uri = new URIish(remoteRepoTextField.getText());
remoteConfig.addURI(uri);
RefSpec spec = new RefSpec("+refs/heads/*:refs/remotes/origin/*");
remoteConfig.addFetchRefSpec(spec);
remoteConfig.update(config);
config.save();
} catch (norepositorySelected | URISyntaxException | IOException e) {
if (logger.isDebugEnabled()) {
logger.debug(e,e);
}
}
dispose();
}
@Test(expected = MissingObjectException.class)
public void testRemoteRepositoryHasNoCommitst()
throws URISyntaxException,IOException,Invalidremoteexception,TransportException,GitAPIException,norepositorySelected {
gitaccess.setRepository(LOCAL_TEST_REPOSITPRY);
final StoredConfig config = gitaccess.getRepository().getConfig();
RemoteConfig remoteConfig = new RemoteConfig(config,"origin");
URIish uri = new URIish(db2.getDirectory().toURI().toURL());
remoteConfig.addURI(uri);
remoteConfig.update(config);
config.save();
gitaccess.add(new FileStatus(GitChangeType.ADD,"test.txt"));
gitaccess.commit("file test added");
// throws missingObjectException
db2.resolve(gitaccess.getLastLocalCommit().getName() + "^{commit}");
}
项目:fabric8-forge
文件:RepositoryResource.java
protected void configureBranch(Git git,String branch) {
// lets update the merge config
if (Strings.isNotBlank(branch)) {
StoredConfig config = git.getRepository().getConfig();
if (Strings.isNullOrBlank(config.getString("branch",branch,"remote")) || Strings.isNullOrBlank(config.getString("branch","merge"))) {
config.setString("branch","remote",getRemote());
config.setString("branch","merge","refs/heads/" + branch);
try {
config.save();
} catch (IOException e) {
LOG.error("Failed to save the git configuration to " + basedir
+ " with branch " + branch + " on remote repo: " + remoteRepository + " due: " + e.getMessage() + ". This exception is ignored.",e);
}
}
}
}
项目:BuilderTools
文件:Builder.java
public static void clone(String url,File target) throws GitAPIException,IOException
{
System.out.println( "Starting clone of " + url + " to " + target );
Git result = Git.cloneRepository().setURI( url ).setDirectory( target ).call();
try
{
StoredConfig config = result.getRepository().getConfig();
config.setBoolean( "core","autocrlf",autocrlf );
config.save();
System.out.println( "Cloned git repository " + url + " to " + target.getAbsolutePath() + ". Current HEAD: " + commitHash( result ) );
} finally
{
result.close();
}
}
项目:release-maven-plugin-parent
文件:GitRelatedTest.java
@Test
public void ifThereIsNoScmInfoAndnoremoteBranchThenAnErrorIsThrown()
throws GitAPIException,InterruptedException {
final TestProject testProject = TestProject.singleModuleProject();
final StoredConfig config = testProject.local.getRepository().getConfig();
config.unsetSection("remote","origin");
config.save();
try {
testProject.mvnRelease("1");
Assert.fail("Should have Failed");
} catch (final MavenExecutionException e) {
assertthat(e.output,oneOf(containsstring("[ERROR] Remote tags Could not be listed!")));
}
}
项目:che
文件:JGitConnection.java
@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;
}
项目:che
文件:JGitConnectionTest.java
@Test
public void shouldCloseCloneCommand() throws Exception {
// given
File fileMock = mock(File.class);
Git cloneCommand = mock(Git.class);
jGitConnection.setoutputLineConsumerFactory(mock(LineConsumerFactory.class));
when(repository.getWorkTree()).thenReturn(fileMock);
when(repository.getDirectory()).thenReturn(fileMock);
when(repository.getConfig()).thenReturn(mock(StoredConfig.class));
doReturn(cloneCommand)
.when(jGitConnection)
.executeRemoteCommand(
nullable(String.class),nullable(TransportCommand.class),nullable(String.class),nullable(String.class));
// when
jGitConnection.clone(CloneParams.create("url").withWorkingDir("fakePath"));
// then
verify(cloneCommand).close();
}
项目:fabric8-devops
文件:GitHelpers.java
public static void configureBranch(Git git,String branch,String origin,String remoteRepository) {
// lets update the merge config
if (!Strings.isNullOrBlank(branch)) {
StoredConfig config = git.getRepository().getConfig();
config.setString("branch",origin);
config.setString("branch","refs/heads/" + branch);
config.setString("remote",origin,"url",remoteRepository);
config.setString("remote","fetch","+refs/heads/*:refs/remotes/" + origin + "/*");
try {
config.save();
} catch (IOException e) {
LOG.error("Failed to save the git configuration to " + git.getRepository().getDirectory()
+ " with branch " + branch + " on " + origin + " remote repo: " + remoteRepository + " due: " + e.getMessage() + ". This exception is ignored.",e);
}
}
}
public List<RefSpec> execute() throws IOException,URISyntaxException {
final List<RefSpec> specs = new ArrayList<>();
if (refSpecs == null || refSpecs.isEmpty()) {
specs.add(new RefSpec("+refs/heads/*:refs/remotes/" + remote.getK1() + "/*"));
specs.add(new RefSpec("+refs/tags/*:refs/tags/*"));
specs.add(new RefSpec("+refs/notes/*:refs/notes/*"));
} else {
specs.addAll(refSpecs);
}
final StoredConfig config = git.getRepository().getConfig();
final String url = config.getString("remote",remote.getK1(),"url");
if (url == null) {
final RemoteConfig remoteConfig = new RemoteConfig(git.getRepository().getConfig(),remote.getK1());
remoteConfig.addURI(new URIish(remote.getK2()));
specs.forEach(remoteConfig::addFetchRefSpec);
remoteConfig.update(git.getRepository().getConfig());
git.getRepository().getConfig().save();
}
return specs;
}
项目:spring-cloud-config
文件:JGitEnvironmentRepositoryTests.java
@Test
public void shouldPullForcepullNotClean() throws Exception {
Git git = mock(Git.class);
StatusCommand statusCommand = mock(StatusCommand.class);
Status status = mock(Status.class);
Repository repository = mock(Repository.class);
StoredConfig storedConfig = mock(StoredConfig.class);
when(git.status()).thenReturn(statusCommand);
when(git.getRepository()).thenReturn(repository);
when(repository.getConfig()).thenReturn(storedConfig);
when(storedConfig.getString("remote","origin","url")).thenReturn("http://example/git");
when(statusCommand.call()).thenReturn(status);
when(status.isClean()).thenReturn(false);
JGitEnvironmentRepository repo = new JGitEnvironmentRepository(this.environment);
repo.setForcePull(true);
boolean shouldPull = repo.shouldPull(git);
assertthat("shouldPull was false",shouldPull,is(true));
}
项目:spring-cloud-config
文件:JGitEnvironmentRepositoryTests.java
@Test
public void shouldPullNotClean() throws Exception {
Git git = mock(Git.class);
StatusCommand statusCommand = mock(StatusCommand.class);
Status status = mock(Status.class);
Repository repository = mock(Repository.class);
StoredConfig storedConfig = mock(StoredConfig.class);
when(git.status()).thenReturn(statusCommand);
when(git.getRepository()).thenReturn(repository);
when(repository.getConfig()).thenReturn(storedConfig);
when(storedConfig.getString("remote","url")).thenReturn("http://example/git");
when(statusCommand.call()).thenReturn(status);
when(status.isClean()).thenReturn(false);
JGitEnvironmentRepository repo = new JGitEnvironmentRepository(this.environment);
boolean shouldPull = repo.shouldPull(git);
assertthat("shouldPull was true",is(false));
}
项目:spring-cloud-config
文件:JGitEnvironmentRepositoryTests.java
@Test
public void shouldPullClean() throws Exception {
Git git = mock(Git.class);
StatusCommand statusCommand = mock(StatusCommand.class);
Status status = mock(Status.class);
Repository repository = mock(Repository.class);
StoredConfig storedConfig = mock(StoredConfig.class);
when(git.status()).thenReturn(statusCommand);
when(git.getRepository()).thenReturn(repository);
when(repository.getConfig()).thenReturn(storedConfig);
when(storedConfig.getString("remote","url")).thenReturn("http://example/git");
when(statusCommand.call()).thenReturn(status);
when(status.isClean()).thenReturn(true);
JGitEnvironmentRepository repo = new JGitEnvironmentRepository(this.environment);
boolean shouldPull = repo.shouldPull(git);
assertthat("shouldPull was false",is(true));
}
项目:tools-idea
文件:GitHttpAdapter.java
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,IGnorECASE_SETTING,Boolean.TRUE.toString());
try {
config.save();
}
catch (IOException e) {
LOG.info("Couldn't save config for " + git.getRepository().getDirectory().getPath(),e);
}
}
项目:gitiles
文件:DefaultAccess.java
private String loadDescriptionText(Repository repo) throws IOException {
String desc = null;
StoredConfig config = repo.getConfig();
IOException configError = null;
try {
config.load();
desc = config.getString("gitweb","description");
} catch (ConfigInvalidException e) {
configError = new IOException(e);
}
if (desc == null) {
File descFile = new File(repo.getDirectory(),"description");
if (descFile.exists()) {
desc = new String(IO.readFully(descFile));
if (DEFAULT_DESCRIPTION.equals(CharMatcher.WHITESPACE.trimFrom(desc))) {
desc = null;
}
} else if (configError != null) {
throw configError;
}
}
return desc;
}
项目:gitblit
文件:GitblitManager.java
@Override
public boolean deleteRegistrations(List<GitblitRegistration> list) {
boolean success = false;
try {
StoredConfig config = getConfig();
for (GitblitRegistration reg : list) {
config.unsetSection(SERVER,reg.name);
registrations.remove(reg.name);
}
config.save();
success = true;
} catch (Throwable t) {
Utils.showException(GitblitManager.this,t);
}
return success;
}
项目:git-client-plugin
文件:JGitAPIImpl.java
private Set<String> listRemoteBranches(String remote) throws NotSupportedException,URISyntaxException {
Set<String> branches = new HashSet<>();
try (final Repository repo = getRepository()) {
StoredConfig config = repo.getConfig();
try (final Transport tn = Transport.open(repo,new URIish(config.getString("remote",remote,"url")))) {
tn.setCredentialsProvider(getProvider());
try (final FetchConnection c = tn.openFetch()) {
for (final Ref r : c.getRefs()) {
if (r.getName().startsWith(R_HEADS))
branches.add("refs/remotes/"+remote+"/"+r.getName().substring(R_HEADS.length()));
}
}
}
}
return branches;
}
项目:IRCBlit
文件:GitblitManager.java
项目:jgit-proxy-clone
文件:Main.java
private void execute() throws Invalidremoteexception,IOException {
setProxy();
CloneCommand cmd = Git.cloneRepository()
.setURI(config.getRemoteUrl());
if (config.getLocalPath() != "") {
cmd.setDirectory(new File(config.getLocalPath()));
}
Git git = cmd.call();
// Set proxy setting to repository config.
StoredConfig gitConfig = git.getRepository().getConfig();
gitConfig.setString("remote","proxy",config.getProxyAddress());
gitConfig.save();
git.getRepository().close();
}
public String getRemoteOriginURL() {
try {
StoredConfig config = getStoredConfig();
String origin = config.getString("remote","url");
if (origin != null && !origin.isEmpty())
return origin;
Set<String> remoteNames = config.getSubsections("remote");
if (remoteNames.size() == 0)
return "";
String url = config.getString("remote",remoteNames.iterator()
.next(),"url");
return url;
} catch (StopTaskException e) {
}
return "";
}
public void setRemote(String remote,String url) throws IOException {
try {
StoredConfig config = getStoredConfig();
Set<String> remoteNames = config.getSubsections("remote");
if (remoteNames.contains(remote)) {
throw new IOException(String.format(
"Remote %s already exists.",remote));
}
config.setString("remote",url);
String fetch = String.format("+refs/heads/*:refs/remotes/%s/*",remote);
config.setString("remote",fetch);
config.save();
mRemotes.add(remote);
} catch (StopTaskException e) {
}
}
/** 저장소 생성함.
* @throws Exception
*/
public boolean createRepository(){
try {
git.init().setBare(true).setDirectory(new File(this.path)).call();
StoredConfig config = localRepo.getConfig();
config.setString("http","receivepack","true");
config.save();
}catch(Exception e) {
System.err.println(e.getMessage());
return false;
}
return true;
}
项目:incubator-netbeans
文件:CreateBranchCommand.java
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,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();
}
}
}
项目:incubator-netbeans
文件:SetUpstreamBranchCommand.java
@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,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);
}
项目:incubator-netbeans
文件:SetUpstreamBranchCommand.java
private void setupRebaseFlag (Repository repository) throws IOException {
StoredConfig config = repository.getConfig();
String autosetupRebase = config.getString(ConfigConstants.CONfig_BRANCH_SECTION,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,rebase);
}
}
项目:incubator-netbeans
文件:BranchTest.java
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,"init");
client.add(new File[] { f },NULL_PROGRESS_MONITOR);
client.commit(new File[] { f },"init commit",NULL_PROGRESS_MONITOR);
client = getClient(workdir);
client.setRemote(new GitRemoteConfig("origin",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,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,false));
client.deleteBranch(BRANCH_NAME,NULL_PROGRESS_MONITOR);
config = repository.getConfig();
config.setString(ConfigConstants.CONfig_BRANCH_SECTION,ConfigConstants.CONfig_KEY_REMOTE);
config.save();
b = client.createBranch(BRANCH_NAME,NULL_PROGRESS_MONITOR);
assertTrue(repository.getConfig().getBoolean(ConfigConstants.CONfig_BRANCH_SECTION,false));
}
项目:incubator-netbeans
文件:BranchTest.java
public void testBranchTracking () throws Exception {
final File otherWT = new File(workdir.getParentFile(),Arrays.asList(otherWT.getAbsolutePath()),Collections.<String>emptyList()),NULL_PROGRESS_MONITOR);
GitBranch b = client.createBranch(Constants.MASTER,NULL_PROGRESS_MONITOR);
assertEquals("origin/master",b.getTrackedBranch().getName());
assertTrue(b.getTrackedBranch().isRemote());
client.checkoutRevision(Constants.MASTER,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,ConfigConstants.CONfig_KEY_AUTOSETUPMERGE,"always");
cfg.save();
b = client.createBranch("nova2",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,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_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_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,"false");
cfg.save();
res = client.blame(f,NULL_PROGRESS_MONITOR);
assertNull(res.getLineDetails(1));
}
项目:incubator-netbeans
文件:StatusTest.java
public void testIgnoreExecutable () throws Exception {
if (isWindows()) {
// no reason to test on win
return;
}
File f = new File(workdir,i am executable");
f.setExecutable(true);
File[] roots = { f };
add(roots);
commit(roots);
GitClient client = getClient(workdir);
Map<File,false);
f.setExecutable(false);
statuses = client.getStatus(roots,false);
StoredConfig config = repository.getConfig();
config.setBoolean(ConfigConstants.CONfig_CORE_SECTION,false);
config.save();
statuses = client.getStatus(roots,false);
config.setBoolean(ConfigConstants.CONfig_CORE_SECTION,true);
config.save();
add(roots);
statuses = client.getStatus(roots,false);
config.save();
add(roots);
statuses = client.getStatus(roots,false);
}
项目:incubator-netbeans
文件:RemotesTest.java
public void testRemoveRemote () throws Exception {
File otherWT = new File(workdir.getParentFile(),NULL_PROGRESS_MONITOR);
RemoteConfig cfg = new RemoteConfig(repository.getConfig(),"origin");
cfg.addURI(new URIish(otherWT.toURI().toURL().toString()));
cfg.addFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/origin/*"));
cfg.update(repository.getConfig());
repository.getConfig().save();
client = getClient(workdir);
client.fetch("origin",NULL_PROGRESS_MONITOR);
client.createBranch("master",NULL_PROGRESS_MONITOR);
client.createBranch("nova",NULL_PROGRESS_MONITOR);
StoredConfig config = repository.getConfig();
assertEquals("+refs/heads/*:refs/remotes/origin/*",config.getString("remote","fetch"));
assertEquals("origin",config.getString("branch","master","remote"));
assertEquals("refs/heads/master","merge"));
assertEquals("origin","nova","merge"));
// Now try to remove the remote
client.removeRemote("origin",NULL_PROGRESS_MONITOR);
config = repository.getConfig();
config.load();
// is everything deleted?
assertEquals(0,config.getSubsections("remote").size());
assertNull(config.getString("branch","remote"));
assertNull(config.getString("branch","merge"));
assertNull(config.getString("branch","merge"));
}
项目:incubator-netbeans
文件:MergeTest.java
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,NULL_PROGRESS_MONITOR);
client.checkoutRevision(BRANCH_NAME,NULL_PROGRESS_MONITOR);
write(f1,BRANCH_NAME);
add(f1);
client.commit(new File[] { f1 },"change on branch",NULL_PROGRESS_MONITOR);
client.checkoutRevision(Constants.MASTER,NULL_PROGRESS_MONITOR);
write(f2,"another change");
add(f2);
client.commit(new File[] { f2 },"change on master",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,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,result.getMergeStatus());
result = client.merge(BRANCH_NAME,GitRepository.FastForwardOption.FAST_FORWARD,NULL_PROGRESS_MONITOR);
// merge commits allowed => OK
assertEquals(MergeStatus.MERGED,result.getMergeStatus());
}