Here are the examples of the java api org.eclipse.jgit.lib.Repository.getConfig() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
76 Examples
19
Source : GitCoreRepository.java
with MIT License
from VirtusLab
with MIT License
from VirtusLab
private Option<String> deriveConfiguredRemoteBranchNameForLocalBranch(String localBranchName) {
return Option.of(jgitRepo.getConfig().getString(CONFIG_BRANCH_SECTION, localBranchName, CONFIG_KEY_MERGE)).map(branchFullName -> branchFullName.replace(Constants.R_HEADS, /* replacement */
""));
}
19
Source : GitCoreRepository.java
with MIT License
from VirtusLab
with MIT License
from VirtusLab
private Option<String> deriveConfiguredRemoteNameForLocalBranch(String localBranchName) {
return Option.of(jgitRepo.getConfig().getString(CONFIG_BRANCH_SECTION, localBranchName, CONFIG_KEY_REMOTE));
}
19
Source : EmbeddedHttpGitServer.java
with Apache License 2.0
from arquillian
with Apache License 2.0
from arquillian
/**
* To allow performing push operations from the cloned repository to remote (served by this server) let's
* skip authorization for HTTP.
*/
private void enableInsecureReceiving(Repository repository) {
final StoredConfig config = repository.getConfig();
config.setBoolean("http", null, "receivepack", true);
try {
config.save();
} catch (IOException e) {
throw new RuntimeException("Unable to save http.receivepack=true config", e);
}
}
19
Source : Utils.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public static boolean checkExecutable(Repository repository) {
return repository.getConfig().getBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_FILEMODE, true);
}
19
Source : Utils.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public static Repository getRepositoryForWorkingDir(File workDir) throws IOException, IllegalArgumentException {
Repository repo = new FileRepositoryBuilder().setWorkTree(workDir).build();
repo.getConfig().setBoolean("pack", null, "buildbitmaps", false);
return repo;
}
18
Source : GitCoreRepository.java
with MIT License
from VirtusLab
with MIT License
from VirtusLab
@Override
public Option<String> deriveConfigValue(String section, String subsection, String name) {
return Option.of(jgitRepo.getConfig().getString(section, subsection, name));
}
18
Source : GitCoreRepository.java
with MIT License
from VirtusLab
with MIT License
from VirtusLab
@Override
public Option<String> deriveConfigValue(String section, String name) {
return Option.of(jgitRepo.getConfig().getString(section, null, name));
}
18
Source : MergeConfig.java
with MIT License
from theonedev
with MIT License
from theonedev
/**
* Get merge configuration for the current branch of the repository
*
* @param repo
* a {@link org.eclipse.jgit.lib.Repository} object.
* @return merge configuration for the current branch of the repository
*/
public static MergeConfig getConfigForCurrentBranch(Repository repo) {
try {
String branch = repo.getBranch();
if (branch != null)
return repo.getConfig().get(getParser(branch));
} catch (IOException e) {
// ignore
}
// use defaults if branch can't be determined
return new MergeConfig();
}
18
Source : DefaultAccess.java
with Apache License 2.0
from google
with Apache License 2.0
from google
private String loadDescriptionText(Repository repo) throws IOException {
String desc = null;
StoredConfig config = repo.getConfig();
IOException configError = null;
try {
config.load();
desc = config.getString("gitweb", null, "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), UTF_8);
if (DEFAULT_DESCRIPTION.equals(CharMatcher.whitespace().trimFrom(desc))) {
desc = null;
}
} else if (configError != null) {
throw configError;
}
}
return desc;
}
18
Source : IgnoreTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
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);
replacedertEquals(new File(workDir, Constants.GITIGNORE_FILENAME), client.ignore(new File[] { f }, NULL_PROGRESS_MONITOR)[0]);
replacedertEquals("/nbproject/file", read(new File(workDir, Constants.GITIGNORE_FILENAME)));
}
18
Source : IgnoreUnignoreCommand.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
private File getGlobalExcludeFile() {
Repository repository = getRepository();
String path = repository.getConfig().get(CoreConfig.KEY).getExcludesFile();
File excludesfile = null;
FS fs = repository.getFS();
if (path != null) {
if (path.startsWith("~/")) {
excludesfile = fs.resolve(fs.userHome(), path.substring(2));
} else {
excludesfile = fs.resolve(null, path);
}
}
return excludesfile;
}
17
Source : GitReceiveHook.java
with MIT License
from scm-manager
with MIT License
from scm-manager
/**
* Resolve the name of the repository.
* This method was introduced to fix issue #415.
*
* @param repository jgit repository
*
* @return name of repository
*
* @throws IOException
*/
private String resolveRepositoryId(Repository repository) {
StoredConfig gitConfig = repository.getConfig();
return handler.getRepositoryId(gitConfig);
}
17
Source : GitUtils.java
with Eclipse Public License 1.0
from eclipse
with Eclipse Public License 1.0
from eclipse
/**
* Returns the Git URL for a given git repository.
* @param db
* @return
*/
public static String getCloneUrl(Repository db) {
StoredConfig config = db.getConfig();
return config.getString(ConfigConstants.CONFIG_REMOTE_SECTION, Constants.DEFAULT_REMOTE_NAME, ConfigConstants.CONFIG_KEY_URL);
}
17
Source : PullTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
private void setupRemoteSpec(String remote, String fetchSpec) throws URISyntaxException, IOException {
RemoteConfig cfg = new RemoteConfig(repository.getConfig(), remote);
cfg.addFetchRefSpec(new RefSpec(fetchSpec));
cfg.update(repository.getConfig());
repository.getConfig().save();
}
16
Source : BaseReceivePackFactory.java
with MIT License
from scm-manager
with MIT License
from scm-manager
private boolean isNonFastForwardAllowed(Repository repository) {
String repositoryId = handler.getRepositoryId(repository.getConfig());
GitRepositoryConfig gitRepositoryConfig = storeProvider.getGitRepositoryConfig(repositoryId);
return !(handler.getConfig().isNonFastForwardDisallowed() || gitRepositoryConfig.isNonFastForwardDisallowed());
}
16
Source : GitMirrorTest.java
with Apache License 2.0
from line
with Apache License 2.0
from line
private static void createGitRepo(Repository gitRepo) throws IOException {
gitRepo.create();
// Disable GPG signing.
final StoredConfig config = gitRepo.getConfig();
config.setBoolean(CONFIG_COMMIT_SECTION, null, CONFIG_KEY_GPGSIGN, false);
config.save();
}
16
Source : IgnoreTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
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);
replacedertEquals(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
replacedertEquals(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/");
replacedertEquals(Status.STATUS_ADDED, client.getStatus(new File[] { f }, NULL_PROGRESS_MONITOR).get(f).getStatusIndexWC());
replacedertEquals(dotGitIgnoreFile, client.ignore(new File[] { f }, NULL_PROGRESS_MONITOR)[0]);
replacedertEquals(Status.STATUS_IGNORED, client.getStatus(new File[] { f }, NULL_PROGRESS_MONITOR).get(f).getStatusIndexWC());
}
16
Source : SetUpstreamBranchCommand.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
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);
}
}
15
Source : GitOperations.java
with MIT License
from Mixeway
with MIT License
from Mixeway
/**
* Get default directory of /opt/sources and try to load active branch, last commitID and repo name from it
*
* @return git info object containing above data
*/
public static GitInformations getGitInformations() {
final Logger log = LoggerFactory.getLogger(GitOperations.clreplaced);
try {
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repository = builder.setGitDir(Paths.get(LOCATION_STATIC + File.separatorChar + ".git").toFile()).readEnvironment().findGitDir().build();
RevCommit latestCommit = new Git(repository).log().setMaxCount(1).call().iterator().next();
String latestCommitHash = latestCommit.getName();
GitInformations gitInformations = GitInformations.builder().branchName(Stream.of(repository.getFullBranch().split("/")).reduce((first, last) -> last).get()).commitId(latestCommitHash).projectName(Stream.of(repository.getConfig().getString("remote", "origin", "url").split("/")).reduce((first, last) -> last).get()).repoUrl(repository.getConfig().getString("remote", "origin", "url")).build();
log.info("[GIT] Processing scan for {} with active branch {} and latest commit {}", gitInformations.getProjectName(), gitInformations.getBranchName(), gitInformations.getCommitId());
return gitInformations;
} catch (IOException | GitAPIException e) {
log.error("[GIT] Unable to load GIT informations reason - {}", e.getLocalizedMessage());
}
return null;
}
15
Source : GetRemotesCommand.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
@Override
protected void run() throws GitException {
Repository repository = getRepository();
try {
List<RemoteConfig> configs = RemoteConfig.getAllRemoteConfigs(repository.getConfig());
remotes = new HashMap<String, GitRemoteConfig>(configs.size());
for (RemoteConfig remote : configs) {
remotes.put(remote.getName(), getClreplacedFactory().createRemoteConfig(remote));
}
} catch (IllegalArgumentException ex) {
if (ex.getMessage().contains("Invalid wildcards")) {
throw new GitException("Unsupported remote definition in " + new File(repository.getDirectory(), "config") + ". Please fix the definition before using remotes.", ex);
}
throw ex;
} catch (URISyntaxException ex) {
throw new GitException(ex);
}
}
15
Source : JGitUtils.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public static boolean isUserSetup(File root) {
Repository repository = getRepository(root);
boolean userExists = true;
if (repository != null) {
try {
StoredConfig config = repository.getConfig();
// NOI18N
String name = config.getString("user", null, "name");
// NOI18N
String email = config.getString("user", null, "email");
if (name == null || name.isEmpty() || email == null || email.isEmpty()) {
userExists = false;
}
} finally {
repository.close();
}
}
return userExists;
}
15
Source : JGitUtils.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public static RepositoryInfo.PushMode getPushMode(File root) {
Repository repository = getRepository(root);
if (repository != null) {
try {
// NOI18N
String val = repository.getConfig().getString("push", null, "default");
if ("upstream".equals(val)) {
// NOI18N
return PushMode.UPSTREAM;
}
} finally {
repository.close();
}
}
return PushMode.ASK;
}
14
Source : GitRemoteHandlerV1.java
with Eclipse Public License 1.0
from eclipse
with Eclipse Public License 1.0
from eclipse
// remove remote
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;
}
14
Source : BranchTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
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);
replacedertEquals(2, branches.size());
replacedertNotNull(branches.get(BRANCH_NAME));
replacedertEquals(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);
replacedertEquals(1, branches.size());
replacedertNull(branches.get(BRANCH_NAME));
}
14
Source : CreateBranchCommand.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
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();
}
}
}
13
Source : BaseReceivePackFactoryTest.java
with MIT License
from scm-manager
with MIT License
from scm-manager
@Before
public void setUpObjectUnderTest() throws Exception {
this.repository = createRepositoryForTesting();
gitConfig = new GitConfig();
when(handler.getConfig()).thenReturn(gitConfig);
when(handler.getRepositoryId(repository.getConfig())).thenReturn("heart-of-gold");
ReceivePack receivePack = new ReceivePack(repository);
when(wrappedReceivePackFactory.create(request, repository)).thenReturn(receivePack);
when(gitRepositoryConfigStoreProvider.getGitRepositoryConfig("heart-of-gold")).thenReturn(gitRepositoryConfig);
factory = new BaseReceivePackFactory<Object>(GitTestHelper.createConverterFactory(), handler, null, gitRepositoryConfigStoreProvider) {
@Override
protected ReceivePack createBasicReceivePack(Object request, Repository repository) throws ServiceNotEnabledException, ServiceNotAuthorizedException {
return wrappedReceivePackFactory.create(request, repository);
}
};
}
13
Source : QuestionnaireGitRepo.java
with Apache License 2.0
from OpenChain-Project
with Apache License 2.0
from OpenChain-Project
/**
* Initializes properties for the clreplaced and refreshes or clones the repository to make it
* current
* @param language Language for the logged in user
* @throws GitRepoException
*/
private void openRepo(String language) throws GitRepoException {
Path gitPath = FileSystems.getDefault().getPath(TMP_DIR).resolve(REPO_DIR_NAME);
workingDir = gitPath.toFile();
// $NON-NLS-1$
File gitDir = gitPath.resolve(".git").toFile();
if (workingDir.exists()) {
if (workingDir.isFile()) {
// Hmmm, I guess we just delete this rather odd file
// $NON-NLS-1$
logger.warn("Unexpected file foundin the git path. Deleting " + gitPath.toString());
if (!workingDir.delete()) {
// $NON-NLS-1$
logger.error("Unable to delete unexpected file foundin the git path " + gitPath.toString());
// $NON-NLS-1$
throw new GitRepoException(I18N.getMessage("QuestionnaireGitRepo.5", language));
}
} else if (workingDir.isDirectory()) {
// Check to see if this is already a repo
try {
RepositoryBuilder builder = new RepositoryBuilder().setGitDir(gitDir);
repo = builder.build();
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
String remoteUrl = repo.getConfig().getString("remote", "origin", "url");
if (QUESTIONAIRRE_URI.equals(remoteUrl)) {
// Matches the remote repo - we can just refresh the directory and return
git = new Git(repo);
refresh(language);
return;
} else {
// $NON-NLS-1$
logger.warn("Found a directory other than the questionnaire repo - deleting and starting from scratch");
repo.close();
repo = null;
deleteDirectory(workingDir, language);
}
} catch (Exception ex) {
// $NON-NLS-1$
logger.warn("Error opening and checking existing repo - starting from scratch", ex);
if (repo != null) {
repo.close();
repo = null;
try {
deleteDirectory(workingDir, language);
} catch (IOException e) {
// $NON-NLS-1$
logger.warn("Unable to delete git repository directory on error", e);
}
}
}
}
}
CloneCommand command = Git.cloneRepository();
try {
Files.createDirectory(gitPath);
command.setDirectory(workingDir);
command.setURI(QUESTIONAIRRE_URI);
git = command.call();
repo = git.getRepository();
} catch (IOException e) {
// $NON-NLS-1$
logger.error("I/O Error cloning repository to directory " + gitPath.toString(), e);
// $NON-NLS-1$
throw new GitRepoException(I18N.getMessage("QuestionnaireGitRepo.6", language), e);
} catch (InvalidRemoteException e) {
// $NON-NLS-1$
logger.error("Unable to access the github repository " + QUESTIONAIRRE_URI, e);
// $NON-NLS-1$
throw new GitRepoException(I18N.getMessage("QuestionnaireGitRepo.7", language), e);
} catch (TransportException e) {
// $NON-NLS-1$
logger.error("Unable to access the github repository (transport error) " + QUESTIONAIRRE_URI, e);
// $NON-NLS-1$
throw new GitRepoException(I18N.getMessage("QuestionnaireGitRepo.7", language), e);
} catch (GitAPIException e) {
// $NON-NLS-1$
logger.error("API error accessing the github repository " + QUESTIONAIRRE_URI, e);
// $NON-NLS-1$
throw new GitRepoException(I18N.getMessage("QuestionnaireGitRepo.7", language), e);
}
}
13
Source : GetSkillDataUrl.java
with GNU Lesser General Public License v2.1
from fossasia
with GNU Lesser General Public License v2.1
from fossasia
@Override
public ServiceResponse serviceImpl(Query call, HttpServletResponse response, Authorization rights, final JsonObjectWithDefault permissions) throws APIException {
JSONObject json = new JSONObject();
try {
// get the repository
Repository repository = SkillTransactions.getPublicRepository();
// get the repository path
String url = repository.getConfig().getString("remote", "origin", "url");
json.put("url", url);
// set the githubrawusercontent path
String rawUserContenturl = url.replace("github.com", "raw.githubusercontent.com");
rawUserContenturl = rawUserContenturl.replace(".git", "");
// get current branch name
String currentBranch = repository.getBranch();
// append branch name in rawUserContenturl
rawUserContenturl = rawUserContenturl + "/" + currentBranch;
json.put("githubusercontent", rawUserContenturl);
json.put("accepted", true);
} catch (IOException e) {
e.printStackTrace();
json.put("accepted", false);
}
return new ServiceResponse(json);
}
13
Source : StatusTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
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);
replacedertStatus(statuses, workDir, f, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false);
f.setExecutable(false);
statuses = client.getStatus(roots, NULL_PROGRESS_MONITOR);
replacedertStatus(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);
replacedertStatus(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);
replacedertStatus(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);
replacedertStatus(statuses, workDir, f, true, Status.STATUS_MODIFIED, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false);
}
13
Source : PullTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
@Override
protected void setUp() throws Exception {
super.setUp();
workDir = getWorkingDirectory();
repository = getRepository(getLocalGitRepository());
otherWT = new File(workDir.getParentFile(), "repo2");
GitClient client = getClient(otherWT);
client.init(NULL_PROGRESS_MONITOR);
f = new File(otherWT, "f");
write(f, "init");
f2 = new File(otherWT, "f2");
write(f2, "init");
client.add(new File[] { f, f2 }, NULL_PROGRESS_MONITOR);
masterInfo = client.commit(new File[] { f, f2 }, "init commit", null, null, NULL_PROGRESS_MONITOR);
branch = client.createBranch(BRANCH_NAME, Constants.MASTER, NULL_PROGRESS_MONITOR);
RemoteConfig cfg = new RemoteConfig(repository.getConfig(), "origin");
cfg.addURI(new URIish(otherWT.toURI().toURL().toString()));
cfg.update(repository.getConfig());
repository.getConfig().save();
}
13
Source : FetchTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
@Override
protected void setUp() throws Exception {
super.setUp();
workDir = getWorkingDirectory();
repository = getRepository(getLocalGitRepository());
otherWT = new File(workDir.getParentFile(), "repo2");
GitClient client = getClient(otherWT);
client.init(NULL_PROGRESS_MONITOR);
f = new File(otherWT, "f");
write(f, "init");
client.add(new File[] { f }, NULL_PROGRESS_MONITOR);
masterInfo = client.commit(new File[] { f }, "init commit", null, null, NULL_PROGRESS_MONITOR);
branch = client.createBranch(BRANCH_NAME, Constants.MASTER, NULL_PROGRESS_MONITOR);
RemoteConfig cfg = new RemoteConfig(repository.getConfig(), "origin");
cfg.addURI(new URIish(otherWT.toURI().toURL().toString()));
cfg.update(repository.getConfig());
repository.getConfig().save();
}
13
Source : CatTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
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"));
replacedertEquals(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"));
replacedertEquals(Arrays.asList(" M f"), res);
runExternally(workDir, Arrays.asList("git.cmd", "add", "f"));
res = runExternally(workDir, Arrays.asList("git.cmd", "status", "-s"));
replacedertEquals(Arrays.asList("M f"), res);
replacedertStatus(client.getStatus(roots, NULL_PROGRESS_MONITOR), workDir, f, true, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_MODIFIED, false);
FileOutputStream fo = new FileOutputStream(f);
client.catFile(f, "HEAD", fo, NULL_PROGRESS_MONITOR);
fo.close();
replacedertStatus(client.getStatus(roots, NULL_PROGRESS_MONITOR), workDir, f, true, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_NORMAL, false);
res = runExternally(workDir, Arrays.asList("git.cmd", "status", "-s"));
replacedertEquals(Arrays.asList("MM f"), res);
client.reset("HEAD", GitClient.ResetType.MIXED, NULL_PROGRESS_MONITOR);
replacedertStatus(client.getStatus(roots, NULL_PROGRESS_MONITOR), workDir, f, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false);
replacedertEquals(e1.getObjectId(), repository.readDirCache().getEntry("f").getObjectId());
res = runExternally(workDir, Arrays.asList("git.cmd", "status", "-s"));
replacedertEquals(0, res.size());
}
13
Source : AddTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
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);
replacedertStatus(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);
replacedertStatus(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);
replacedertStatus(statuses, workDir, f, true, Status.STATUS_ADDED, Status.STATUS_MODIFIED, Status.STATUS_ADDED, false);
}
13
Source : AddTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
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);
replacedertStatus(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);
replacedertStatus(statuses, workDir, f, true, Status.STATUS_MODIFIED, Status.STATUS_MODIFIED, Status.STATUS_MODIFIED, false);
}
13
Source : AddTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
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);
replacedertStatus(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);
replacedertStatus(statuses, workDir, f, true, Status.STATUS_ADDED, Status.STATUS_MODIFIED, Status.STATUS_ADDED, false);
}
13
Source : CreateBranchCommand.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
private boolean createBranchInEmptyRepository(Repository repository) throws GitException {
// is this an empty repository after a fresh clone of an empty repository?
if (revision.startsWith(Constants.R_REMOTES)) {
try {
if (Utils.parseObjectId(repository, Constants.HEAD) == null) {
StoredConfig config = repository.getConfig();
String[] elements = revision.split("/", 4);
String remoteName = elements[2];
String remoteBranchName = elements[3];
config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_REMOTE, remoteName);
config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_MERGE, Constants.R_HEADS + remoteBranchName);
config.save();
return true;
}
} catch (IOException ex) {
throw new GitException(ex);
} catch (GitException ex) {
throw ex;
}
}
return false;
}
13
Source : CatCommand.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
private void catIndexEntry() throws GitException {
Repository repository = getRepository();
OutputStream out = null;
try {
DirCache cache = repository.readDirCache();
int pos = cache.findEntry(relativePath);
DirCacheEntry entry = null;
if (pos >= 0) {
DirCacheEntry e = cache.getEntry(pos);
do {
if (stage == e.getStage()) {
entry = e;
}
} while (entry == null && ++pos < cache.getEntryCount() && relativePath.equals((e = cache.getEntry(pos)).getPathString()));
}
found = false;
if (entry != null) {
found = true;
WorkingTreeOptions opt = repository.getConfig().get(WorkingTreeOptions.KEY);
ObjectLoader loader = repository.getObjectDatabase().open(entry.getObjectId());
if (opt.getAutoCRLF() != CoreConfig.AutoCRLF.FALSE) {
out = new AutoCRLFOutputStream(os);
} else {
out = os;
}
loader.copyTo(os);
found = true;
}
} catch (NoWorkTreeException ex) {
throw new GitException(ex);
} catch (IOException ex) {
throw new GitException(ex);
} finally {
try {
if (out == null) {
os.close();
} else {
out.close();
}
} catch (IOException ex) {
//
}
}
}
12
Source : GitSubmoduleTest.java
with Eclipse Public License 1.0
from eclipse
with Eclipse Public License 1.0
from eclipse
@Test
public void testSyncSubmodule() throws IOException, SAXException, JSONException, CoreException, ConfigInvalidException {
createWorkspace(SimpleMetaStore.DEFAULT_WORKSPACE_NAME);
String workspaceId = getWorkspaceId(workspaceLocation);
JSONObject project = createProjectOrLink(workspaceLocation, getMethodName().concat("Project1"), null);
JSONObject clone = clone(workspaceId, project);
String contentLocation = clone.getString(ProtocolConstants.KEY_CONTENT_LOCATION);
String submoduleLocation = clone.getString(GitConstants.KEY_SUBMODULE);
String location = clone.getString(ProtocolConstants.KEY_LOCATION);
Repository repository = getRepositoryForContentLocation(contentLocation);
File file = new File(repository.getWorkTree(), DOT_GIT_MODULES);
replacedertFalse(file.exists());
URIish uri = new URIish(gitDir.toURI().toURL());
WebRequest request = postSubmoduleRequest(submoduleLocation, "test", uri.toString(), location);
WebResponse response = webConversation.getResponse(request);
file = new File(repository.getWorkTree(), DOT_GIT_MODULES);
replacedertTrue(file.exists());
replacedertNotNull(repository);
StoredConfig repoConfig = repository.getConfig();
String originalUrl = repoConfig.getString("submodule", "test", "url");
repoConfig.setString("submodule", "test", "url", "value");
repoConfig.save();
replacedertEquals(repoConfig.getString("submodule", "test", "url"), "value");
WebRequest reqSync = putSubmoduleRequest(submoduleLocation, "sync");
WebResponse resSync = webConversation.getResponse(reqSync);
repoConfig = repository.getConfig();
replacedertEquals(repoConfig.getString("submodule", "test", "url"), originalUrl);
}
12
Source : GitSubmoduleHandlerV1.java
with Eclipse Public License 1.0
from eclipse
with Eclipse Public License 1.0
from eclipse
public static void removeSubmodule(Repository db, Repository parentRepo, String pathToSubmodule) throws Exception {
pathToSubmodule = pathToSubmodule.replace("\\", "/");
StoredConfig gitSubmodulesConfig = getGitSubmodulesConfig(parentRepo);
gitSubmodulesConfig.unsetSection(CONFIG_SUBMODULE_SECTION, pathToSubmodule);
gitSubmodulesConfig.save();
StoredConfig repositoryConfig = parentRepo.getConfig();
repositoryConfig.unsetSection(CONFIG_SUBMODULE_SECTION, pathToSubmodule);
repositoryConfig.save();
Git git = Git.wrap(parentRepo);
git.add().addFilepattern(DOT_GIT_MODULES).call();
RmCommand rm = git.rm().addFilepattern(pathToSubmodule);
if (gitSubmodulesConfig.getSections().size() == 0) {
rm.addFilepattern(DOT_GIT_MODULES);
}
rm.call();
FileUtils.delete(db.getWorkTree(), FileUtils.RECURSIVE);
FileUtils.delete(db.getDirectory(), FileUtils.RECURSIVE);
}
12
Source : SetUpstreamBranchTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
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);
replacedertTrue(branches.containsKey("origin/master"));
replacedertNull(branches.get("master").getTrackedBranch());
// set tracking
GitBranch b = client.setUpstreamBranch("master", "origin/master", NULL_PROGRESS_MONITOR);
replacedertEquals("origin/master", b.getTrackedBranch().getName());
Config cfg = repository.getConfig();
replacedertEquals(".", cfg.getString(ConfigConstants.CONFIG_BRANCH_SECTION, "master", ConfigConstants.CONFIG_KEY_REMOTE));
replacedertEquals("refs/remotes/origin/master", cfg.getString(ConfigConstants.CONFIG_BRANCH_SECTION, "master", ConfigConstants.CONFIG_KEY_MERGE));
}
12
Source : RemotesTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testAddRemote() throws Exception {
StoredConfig config = repository.getConfig();
replacedertEquals(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(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");
replacedertEquals(Arrays.asList(new URIish(new File(workDir.getParentFile(), "repo2").toURI().toString())), cfg.getURIs());
replacedertEquals(Arrays.asList(new URIish(new File(workDir.getParentFile(), "repo2").toURI().toString())), cfg.getPushURIs());
replacedertEquals(Arrays.asList(new RefSpec("+refs/heads/*:refs/remotes/origin/*")), cfg.getFetchRefSpecs());
replacedertEquals(Arrays.asList(new RefSpec("refs/remotes/origin/*:+refs/heads/*")), cfg.getPushRefSpecs());
}
12
Source : BlameTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
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();
replacedertEquals(info.getRevision(), blameResult.getSourceCommit(1).getName());
GitBlameResult res = client.blame(f, null, NULL_PROGRESS_MONITOR);
replacedertNull(res.getLineDetails(0));
replacedertLineDetails(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);
replacedertNull(res.getLineDetails(1));
}
12
Source : InitRepositoryCommand.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
@Override
protected void run() throws GitException {
Repository repository = getRepository();
try {
if (!(workDir.exists() || workDir.mkdirs())) {
// NOI18N
throw new GitException(MessageFormat.format(Utils.getBundle(InitRepositoryCommand.clreplaced).getString("MSG_Exception_CannotCreateFolder"), workDir.getAbsolutePath()));
}
repository.create();
StoredConfig cfg = repository.getConfig();
cfg.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_BARE, false);
cfg.unset(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOCRLF);
cfg.save();
} catch (IllegalStateException ex) {
throw new GitException(ex);
} catch (IOException ex) {
throw new GitException(ex);
}
}
12
Source : CatCommand.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
private void catFromRevision() throws GitException.MissingObjectException, GitException {
Repository repository = getRepository();
OutputStream out = null;
try {
RevCommit commit = Utils.findCommit(repository, revision);
TreeWalk walk = new TreeWalk(repository);
walk.reset();
walk.addTree(commit.getTree());
walk.setFilter(PathFilter.create(relativePath));
walk.setRecursive(true);
found = false;
while (!found && walk.next() && !monitor.isCanceled()) {
if (relativePath.equals(walk.getPathString())) {
WorkingTreeOptions opt = repository.getConfig().get(WorkingTreeOptions.KEY);
ObjectLoader loader = repository.getObjectDatabase().open(walk.getObjectId(0));
if (opt.getAutoCRLF() != CoreConfig.AutoCRLF.FALSE) {
out = new AutoCRLFOutputStream(os);
} else {
out = os;
}
loader.copyTo(os);
found = true;
}
}
} catch (MissingObjectException ex) {
throw new GitException(ex);
} catch (IOException ex) {
throw new GitException(ex);
} finally {
try {
if (out == null) {
os.close();
} else {
out.close();
}
} catch (IOException ex) {
//
}
}
}
12
Source : JGitUtils.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public static void persistUser(File root, GitUser author) throws GitException {
Repository repository = getRepository(root);
if (repository != null) {
try {
StoredConfig config = repository.getConfig();
// NOI18N
config.setString("user", null, "name", author.getName());
// NOI18N
config.setString("user", null, "email", author.getEmailAddress());
try {
config.save();
FileUtil.refreshFor(new File(GitUtils.getGitFolderForRoot(root), "config"));
} catch (IOException ex) {
throw new GitException(ex);
}
} finally {
repository.close();
}
}
}
11
Source : CheckoutRevisionCommand.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
private void resolveEntries(MergeAlgorithm merger, String path, DirCacheEntry[] entries, ObjectDatabase db, DirCacheBuilder builder) throws IOException {
if (entries[0] == null && entries[1] == null && entries[2] == null) {
return;
}
DirCacheEntry base = entries[0];
DirCacheEntry theirs = entries[2];
ObjectId oursId = cachedContents.get(path);
Repository repository = getRepository();
boolean added = false;
if (oursId != null) {
if (theirs != null && (theirs.getFileMode().getBits() & FileMode.TYPE_FILE) == FileMode.TYPE_FILE) {
RawText baseText = base == null ? RawText.EMPTY_TEXT : Utils.getRawText(base.getObjectId(), db);
RawText ourText = Utils.getRawText(oursId, db);
RawText theirsText = Utils.getRawText(theirs.getObjectId(), db);
MergeResult<RawText> merge = merger.merge(RawTextComparator.DEFAULT, baseText, ourText, theirsText);
checkoutFile(merge, path);
if (!merge.containsConflicts()) {
added = true;
DirCacheEntry e = new DirCacheEntry(path);
e.setCreationTime(theirs.getCreationTime());
e.setFileMode(theirs.getFileMode());
e.setLastModified(theirs.getLastModified());
e.setLength(theirs.getLength());
e.setObjectId(theirs.getObjectId());
builder.add(e);
}
} else {
File file = new File(getRepository().getWorkTree(), path);
file.getParentFile().mkdirs();
WorkingTreeOptions opt = repository.getConfig().get(WorkingTreeOptions.KEY);
ObjectLoader loader = repository.getObjectDatabase().open(oursId);
try (OutputStream fos = opt.getAutoCRLF() != CoreConfig.AutoCRLF.FALSE ? new AutoCRLFOutputStream(new FileOutputStream(file)) : new FileOutputStream(file)) {
loader.copyTo(fos);
}
}
}
if (!added) {
for (DirCacheEntry e : entries) {
if (e != null) {
builder.add(e);
}
}
}
entries[0] = entries[1] = entries[2] = null;
}
10
Source : CreateClientTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
/**
* Submodules have .git folder elsewhere, they use GIT_LINK mechanism to access it
*/
public void testClientForSubmodule() throws Exception {
File subRepo = new File(workDir, "subrepo");
subRepo.mkdirs();
File newFile = new File(subRepo, "file");
newFile.createNewFile();
File[] roots = new File[] { newFile };
GitClient client = GitRepository.getInstance(subRepo).createClient();
client.init(NULL_PROGRESS_MONITOR);
client.add(roots, NULL_PROGRESS_MONITOR);
Map<File, GitStatus> statuses = client.getStatus(new File[] { newFile }, NULL_PROGRESS_MONITOR);
replacedertStatus(statuses, subRepo, newFile, true, GitStatus.Status.STATUS_ADDED, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_ADDED, false);
Repository repo = getRepository(client);
StoredConfig config = repo.getConfig();
config.setString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_WORKTREE, subRepo.getAbsolutePath());
config.save();
File gitFolder = new File(subRepo, ".git");
File newLocation = new File(workDir.getParentFile(), "newFolder");
newLocation.mkdirs();
gitFolder.renameTo(new File(newLocation, ".git"));
gitFolder = new File(newLocation, ".git");
File gitFile = new File(subRepo, ".git");
write(gitFile, "gitdir: " + gitFolder.getAbsolutePath());
ApiUtils.clearRepositoryPool();
client = GitRepository.getInstance(subRepo).createClient();
repo = getRepository(client);
replacedertEquals(subRepo, repo.getWorkTree());
replacedertEquals(gitFolder, repo.getDirectory());
statuses = client.getStatus(new File[] { newFile }, NULL_PROGRESS_MONITOR);
replacedertStatus(statuses, subRepo, newFile, true, GitStatus.Status.STATUS_ADDED, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_ADDED, false);
}
10
Source : SubmoduleTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
@Override
protected void setUp() throws Exception {
super.setUp();
workDir = getWorkingDirectory();
repository = getRepository(getLocalGitRepository());
moduleRepo = new File(workDir.getParentFile(), "module");
GitClient client = getClient(moduleRepo);
client.init(NULL_PROGRESS_MONITOR);
submoduleRepo1 = new File(workDir.getParentFile(), "submodule1");
client = getClient(submoduleRepo1);
client.init(NULL_PROGRESS_MONITOR);
submoduleRepo2 = new File(workDir.getParentFile(), "submodule2");
client = getClient(submoduleRepo2);
client.init(NULL_PROGRESS_MONITOR);
client = getClient(workDir);
f = new File(workDir, "f");
write(f, "init");
client.add(new File[] { f }, NULL_PROGRESS_MONITOR);
client.commit(new File[] { f }, "init commit", null, null, NULL_PROGRESS_MONITOR);
RemoteConfig cfg = new RemoteConfig(repository.getConfig(), "origin");
cfg.addURI(new URIish(moduleRepo.toURI().toURL().toString()));
cfg.update(repository.getConfig());
repository.getConfig().save();
client.push("origin", Arrays.asList("refs/heads/master:refs/heads/master"), Arrays.asList("+refs/heads/master:refs/remotes/origin/master"), NULL_PROGRESS_MONITOR);
File submodules = new File(workDir, "submodules");
submoduleFolder1 = new File(submodules, "submodule1");
submoduleFolder1.mkdirs();
getClient(submoduleFolder1).init(NULL_PROGRESS_MONITOR);
f1 = new File(submoduleFolder1, "file");
write(f1, "init");
getClient(submoduleFolder1).add(new File[] { f1 }, NULL_PROGRESS_MONITOR);
getClient(submoduleFolder1).commit(new File[] { f1 }, "init SM1 commit", null, null, NULL_PROGRESS_MONITOR);
repositorySM1 = getRepository(getClient(submoduleFolder1));
cfg = new RemoteConfig(repositorySM1.getConfig(), "origin");
cfg.addURI(new URIish(submoduleRepo1.toURI().toURL().toString()));
cfg.update(repositorySM1.getConfig());
repositorySM1.getConfig().save();
getClient(submoduleFolder1).push("origin", Arrays.asList("refs/heads/master:refs/heads/master"), Arrays.asList("+refs/heads/master:refs/remotes/origin/master"), NULL_PROGRESS_MONITOR);
submoduleFolder2 = new File(submodules, "submodule2");
submoduleFolder2.mkdirs();
getClient(submoduleFolder2).init(NULL_PROGRESS_MONITOR);
f2 = new File(submoduleFolder2, "file");
write(f2, "init");
getClient(submoduleFolder2).add(new File[] { f2 }, NULL_PROGRESS_MONITOR);
getClient(submoduleFolder2).commit(new File[] { f2 }, "init SM1 commit", null, null, NULL_PROGRESS_MONITOR);
repositorySM2 = getRepository(getClient(submoduleFolder2));
cfg = new RemoteConfig(repositorySM2.getConfig(), "origin");
cfg.addURI(new URIish(submoduleRepo2.toURI().toURL().toString()));
cfg.update(repositorySM2.getConfig());
repositorySM2.getConfig().save();
getClient(submoduleFolder2).push("origin", Arrays.asList("refs/heads/master:refs/heads/master"), Arrays.asList("+refs/heads/master:refs/remotes/origin/master"), NULL_PROGRESS_MONITOR);
}
10
Source : SetUpstreamBranchTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
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);
replacedertTrue(branches.containsKey("origin/master"));
replacedertNull(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);
replacedertEquals("origin/master", b.getTrackedBranch().getName());
config = repository.getConfig();
replacedertEquals("origin", config.getString(ConfigConstants.CONFIG_BRANCH_SECTION, "master", ConfigConstants.CONFIG_KEY_REMOTE));
replacedertEquals("refs/heads/master", config.getString(ConfigConstants.CONFIG_BRANCH_SECTION, "master", ConfigConstants.CONFIG_KEY_MERGE));
replacedertFalse(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);
replacedertEquals("origin/master", b.getTrackedBranch().getName());
config = repository.getConfig();
replacedertEquals("origin", config.getString(ConfigConstants.CONFIG_BRANCH_SECTION, "master", ConfigConstants.CONFIG_KEY_REMOTE));
replacedertEquals("refs/heads/master", config.getString(ConfigConstants.CONFIG_BRANCH_SECTION, "master", ConfigConstants.CONFIG_KEY_MERGE));
replacedertTrue(config.getBoolean(ConfigConstants.CONFIG_BRANCH_SECTION, "master", ConfigConstants.CONFIG_KEY_REBASE, false));
}
10
Source : RemotesTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testUpdateRemoteRollback() throws Exception {
StoredConfig config = repository.getConfig();
RemoteConfig cfg = new RemoteConfig(config, "origin");
cfg.addURI(new URIish("blablabla"));
cfg.setFetchRefSpecs(Arrays.asList(new RefSpec("refs/heads/master:refs/remotes/origin/master")));
cfg.update(config);
config.save();
config.load();
replacedertEquals(1, config.getSubsections("remote").size());
GitClient client = getClient(workDir);
GitRemoteConfig remoteConfig = new GitRemoteConfig("origin", Arrays.asList(new File(workDir.getParentFile(), "repo2").toURI().toString()), Arrays.asList(new File(workDir.getParentFile(), "repo2").toURI().toString()), Arrays.asList("+refs/heads/*:refs/remotes/origin/master"), Arrays.asList("refs/remotes/origin/*:+refs/heads/*"));
// an error while setting the remote must result in the rollback of the modification
try {
client.setRemote(remoteConfig, NULL_PROGRESS_MONITOR);
} catch (GitException ex) {
}
cfg = new RemoteConfig(config, "origin");
replacedertEquals(Arrays.asList(new URIish("blablabla")), cfg.getURIs());
replacedertEquals(Arrays.asList(new RefSpec("refs/heads/master:refs/remotes/origin/master")), cfg.getFetchRefSpecs());
}
See More Examples