本文整理汇总了Java中git4idea.config.GitConfigUtil类的典型用法代码示例。如果您正苦于以下问题:Java GitConfigUtil类的具体用法?Java GitConfigUtil怎么用?Java GitConfigUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GitConfigUtil类属于git4idea.config包,在下文中一共展示了GitConfigUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDefaultMessageFor
import git4idea.config.GitConfigUtil; //导入依赖的package包/类
@Nullable
public String getDefaultMessageFor(FilePath[] filesToCheckin) {
LinkedHashSet<String> messages = ContainerUtil.newLinkedHashSet();
for (VirtualFile root : GitUtil.gitRoots(Arrays.asList(filesToCheckin))) {
VirtualFile mergeMsg = root.findFileByRelativePath(GitRepositoryFiles.GIT_MERGE_MSG);
VirtualFile squashMsg = root.findFileByRelativePath(GitRepositoryFiles.GIT_SQUASH_MSG);
try {
if (mergeMsg == null && squashMsg == null) {
continue;
}
String encoding = GitConfigUtil.getCommitEncoding(myProject, root);
if (mergeMsg != null) {
messages.add(loadMessage(mergeMsg, encoding));
}
else {
messages.add(loadMessage(squashMsg, encoding));
}
}
catch (IOException e) {
if (log.isDebugEnabled()) {
log.debug("Unable to load merge message", e);
}
}
}
return DvcsUtil.joinMessagesOrNull(messages);
}
示例2: tracked
import git4idea.config.GitConfigUtil; //导入依赖的package包/类
/**
* Get the tracking branch for the given branch, or null if the given branch doesn't track anything.
* @deprecated Use {@link GitConfig#getBranchTrackInfos()}
*/
@Deprecated
@Nullable
public static GitRemoteBranch tracked(@NotNull Project project, @NotNull VirtualFile root, @NotNull String branchName) throws VcsException {
final HashMap<String, String> result = new HashMap<String, String>();
GitConfigUtil.getValues(project, root, null, result);
String remoteName = result.get(trackedRemoteKey(branchName));
if (remoteName == null) {
return null;
}
String branch = result.get(trackedBranchKey(branchName));
if (branch == null) {
return null;
}
if (".".equals(remoteName)) {
return new GitSvnRemoteBranch(branch, GitBranch.DUMMY_HASH);
}
GitRemote remote = findRemoteByNameOrLogError(project, root, remoteName);
if (remote == null) return null;
return new GitStandardRemoteBranch(remote, branch, GitBranch.DUMMY_HASH);
}
示例3: setUpstream
import git4idea.config.GitConfigUtil; //导入依赖的package包/类
private static void setUpstream(@NotNull GitRepository repository,
@NotNull GitLocalBranch source, @NotNull GitRemote remote, @NotNull GitRemoteBranch dest) {
if (!branchTrackingInfoIsSet(repository, source)) {
Project project = repository.getProject();
VirtualFile root = repository.getRoot();
String branchName = source.getName();
try {
boolean rebase = getMergeOrRebaseConfig(project, root);
GitConfigUtil.setValue(project, root, "branch." + branchName + ".remote", remote.getName());
GitConfigUtil.setValue(project, root, "branch." + branchName + ".merge",
GitBranch.REFS_HEADS_PREFIX + dest.getNameForRemoteOperations());
if (rebase) {
GitConfigUtil.setValue(project, root, "branch." + branchName + ".rebase", "true");
}
}
catch (VcsException e) {
LOG.error(String.format("Couldn't set up tracking for source branch %s, target branch %s, remote %s in root %s",
source, dest, remote, repository), e);
Notificator.getInstance(project).notify(GitVcs.NOTIFICATION_GROUP_ID, "", "Couldn't set up branch tracking",
NotificationType.ERROR);
}
}
}
示例4: loadStashStackAsCommits
import git4idea.config.GitConfigUtil; //导入依赖的package包/类
@Nullable
public static List<Pair<String, GitHeavyCommit>> loadStashStackAsCommits(@NotNull Project project, @NotNull VirtualFile root,
SymbolicRefsI refs, final String... parameters) throws VcsException {
GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.STASH.readLockingCommand());
GitLogParser parser = new GitLogParser(project, GitLogParser.NameStatus.STATUS, SHORT_HASH, HASH, COMMIT_TIME, AUTHOR_NAME, AUTHOR_TIME, AUTHOR_EMAIL, COMMITTER_NAME,
COMMITTER_EMAIL, SHORT_PARENTS, REF_NAMES, SHORT_REF_LOG_SELECTOR, SUBJECT, BODY, RAW_BODY);
h.setSilent(true);
h.addParameters("list");
h.addParameters(parameters);
h.addParameters(parser.getPretty());
String out;
h.setCharset(Charset.forName(GitConfigUtil.getLogEncoding(project, root)));
out = h.run();
final List<GitLogRecord> gitLogRecords = parser.parse(out);
final List<Pair<String, GitHeavyCommit>> result = new ArrayList<Pair<String, GitHeavyCommit>>();
for (GitLogRecord gitLogRecord : gitLogRecords) {
ProgressManager.checkCanceled();
final GitHeavyCommit gitCommit = createCommit(project, refs, root, gitLogRecord);
result.add(new Pair<String, GitHeavyCommit>(gitLogRecord.getShortenedRefLog(), gitCommit));
}
return result;
}
示例5: getRefs
import git4idea.config.GitConfigUtil; //导入依赖的package包/类
public CachedRefs getRefs() throws VcsException {
final CachedRefs refs = new CachedRefs();
GitRepository repository = getRepositoryWise(myProject, myRoot);
GitBranchesCollection branches = repository.getBranches();
refs.setCollection(branches);
final GitBranch current = repository.getCurrentBranch();
refs.setCurrentBranch(current);
if (current != null) {
final Collection<GitBranchTrackInfo> infos = repository.getBranchTrackInfos();
for (GitBranchTrackInfo info : infos) {
if (info.getLocalBranch().equals(current)) {
String fullName = info.getRemoteBranch().getFullName();
fullName = fullName.startsWith(GitBranch.REFS_REMOTES_PREFIX)
? fullName.substring(GitBranch.REFS_REMOTES_PREFIX.length()) : fullName;
refs.setTrackedRemoteName(fullName);
break;
}
}
}
refs.setUsername(GitConfigUtil.getValue(myProject, myRoot, GitConfigUtil.USER_NAME));
final String head = repository.getCurrentRevision();
if (head != null) {
refs.setHeadHash(AbstractHash.create(head));
}
return refs;
}
示例6: setGitIdentity
import git4idea.config.GitConfigUtil; //导入依赖的package包/类
protected void setGitIdentity(VirtualFile root) {
try {
GitConfigUtil.setValue(myProject, root, "user.name", "Github Test");
GitConfigUtil.setValue(myProject, root, "user.email", "[email protected]");
}
catch (VcsException e) {
e.printStackTrace();
}
}
示例7: setCoreAutoCrlfAttribute
import git4idea.config.GitConfigUtil; //导入依赖的package包/类
private void setCoreAutoCrlfAttribute(@NotNull VirtualFile aRoot) {
try {
GitConfigUtil.setValue(myProject, aRoot, GitConfigUtil.CORE_AUTOCRLF, GitCrlfUtil.RECOMMENDED_VALUE, "--global");
}
catch (VcsException e) {
// it is not critical: the user just will get the dialog again next time
LOG.warn("Couldn't globally set core.autocrlf in " + aRoot, e);
}
}
示例8: setUserNameUnderProgress
import git4idea.config.GitConfigUtil; //导入依赖的package包/类
private boolean setUserNameUnderProgress(@NotNull final Project project,
@NotNull final Collection<VirtualFile> notDefined,
@NotNull final GitUserNameNotDefinedDialog dialog) {
final Ref<String> error = Ref.create();
ProgressManager.getInstance().run(new Task.Modal(project, "Setting Git User Name...", true) {
@Override
public void run(@NotNull ProgressIndicator pi) {
try {
if (dialog.isGlobal()) {
GitConfigUtil.setValue(project, notDefined.iterator().next(), GitConfigUtil.USER_NAME, dialog.getUserName(), "--global");
GitConfigUtil.setValue(project, notDefined.iterator().next(), GitConfigUtil.USER_EMAIL, dialog.getUserEmail(), "--global");
}
else {
for (VirtualFile root : notDefined) {
GitConfigUtil.setValue(project, root, GitConfigUtil.USER_NAME, dialog.getUserName());
GitConfigUtil.setValue(project, root, GitConfigUtil.USER_EMAIL, dialog.getUserEmail());
}
}
}
catch (VcsException e) {
String message = "Couldn't set user.name and user.email";
LOG.error(message, e);
error.set(message);
}
}
});
if (error.isNull()) {
return true;
}
else {
Messages.showErrorDialog(myPanel.getComponent(), error.get());
return false;
}
}
示例9: createMessageFile
import git4idea.config.GitConfigUtil; //导入依赖的package包/类
/**
* Create a file that contains the specified message
*
* @param root a git repository root
* @param message a message to write
* @return a file reference
* @throws IOException if file cannot be created
*/
private File createMessageFile(VirtualFile root, final String message) throws IOException {
// filter comment lines
File file = FileUtil.createTempFile(GIT_COMMIT_MSG_FILE_PREFIX, GIT_COMMIT_MSG_FILE_EXT);
file.deleteOnExit();
@NonNls String encoding = GitConfigUtil.getCommitEncoding(myProject, root);
Writer out = new OutputStreamWriter(new FileOutputStream(file), encoding);
try {
out.write(message);
}
finally {
out.close();
}
return file;
}
示例10: isAutoCrlfSetRight
import git4idea.config.GitConfigUtil; //导入依赖的package包/类
private boolean isAutoCrlfSetRight(@NotNull VirtualFile root) {
GitRepository repository = myPlatformFacade.getRepositoryManager(myProject).getRepositoryForRoot(root);
if (repository == null) {
LOG.warn("Repository is null for " + root);
return true;
}
GitCommandResult result = myGit.config(repository, GitConfigUtil.CORE_AUTOCRLF);
String value = result.getOutputAsJoinedString();
return value.equalsIgnoreCase("true") || value.equalsIgnoreCase("input");
}
示例11: resolveUpdateMethod
import git4idea.config.GitConfigUtil; //导入依赖的package包/类
@NotNull
public static UpdateMethod resolveUpdateMethod(@NotNull Project project, @NotNull VirtualFile root) {
GitLocalBranch branch = GitBranchUtil.getCurrentBranch(project, root);
boolean rebase = false;
if (branch != null) {
try {
String rebaseValue = GitConfigUtil.getValue(project, root, "branch." + branch.getName() + ".rebase");
rebase = rebaseValue != null && rebaseValue.equalsIgnoreCase("true");
}
catch (VcsException e) {
LOG.warn("Couldn't get git config branch." + branch.getName() + ".rebase", e);
}
}
return rebase ? UpdateMethod.REBASE : UpdateMethod.MERGE;
}
示例12: GitRebaseUnstructuredEditor
import git4idea.config.GitConfigUtil; //导入依赖的package包/类
/**
* The constructor
*
* @param project the context project
* @param root the Git root
* @param path the path to edit
* @throws IOException if there is an IO problem
*/
protected GitRebaseUnstructuredEditor(Project project, VirtualFile root, String path) throws IOException {
super(project, true);
setTitle(GitBundle.message("rebase.unstructured.editor.title"));
setOKButtonText(GitBundle.message("rebase.unstructured.editor.button"));
myGitRootLabel.setText(root.getPresentableUrl());
encoding = GitConfigUtil.getCommitEncoding(project, root);
myFile = new File(path);
myTextArea.setText(FileUtil.loadFile(myFile, encoding));
myTextArea.setCaretPosition(0);
init();
}
示例13: updateTrackedBranch
import git4idea.config.GitConfigUtil; //导入依赖的package包/类
/**
* Update tracked branch basing on the currently selected branch
*/
private void updateTrackedBranch() {
try {
final VirtualFile root = gitRoot();
String currentBranch = (String)myBranchComboBox.getSelectedItem();
GitBranch trackedBranch = null;
if (currentBranch != null) {
String remote = GitConfigUtil.getValue(myProject, root, "branch." + currentBranch + ".remote");
String mergeBranch = GitConfigUtil.getValue(myProject, root, "branch." + currentBranch + ".merge");
if (remote == null || mergeBranch == null) {
trackedBranch = null;
}
else {
mergeBranch = GitBranchUtil.stripRefsPrefix(mergeBranch);
if (remote.equals(".")) {
trackedBranch = new GitSvnRemoteBranch(mergeBranch, GitBranch.DUMMY_HASH);
}
else {
GitRemote r = GitBranchUtil.findRemoteByNameOrLogError(myProject, root, remote);
if (r != null) {
trackedBranch = new GitStandardRemoteBranch(r, mergeBranch, GitBranch.DUMMY_HASH);
}
}
}
}
if (trackedBranch != null) {
myOntoComboBox.setSelectedItem(trackedBranch);
}
else {
GitUIUtil.getTextField(myOntoComboBox).setText("");
}
GitUIUtil.getTextField(myFromComboBox).setText("");
}
catch (VcsException e) {
GitUIUtil.showOperationError(myProject, e, "git config");
}
}
示例14: load
import git4idea.config.GitConfigUtil; //导入依赖的package包/类
@NotNull
public List<GitRebaseEntry> load() throws IOException, NoopException {
String encoding = GitConfigUtil.getLogEncoding(myProject, myRoot);
List<GitRebaseEntry> entries = ContainerUtil.newArrayList();
final StringScanner s = new StringScanner(FileUtil.loadFile(new File(myFile), encoding));
boolean noop = false;
while (s.hasMoreData()) {
if (s.isEol() || s.startsWith('#')) {
s.nextLine();
continue;
}
if (s.startsWith("noop")) {
noop = true;
s.nextLine();
continue;
}
String action = s.spaceToken();
String hash = s.spaceToken();
String comment = s.line();
entries.add(new GitRebaseEntry(action, hash, comment));
}
if (noop && entries.isEmpty()) {
throw new NoopException();
}
return entries;
}
示例15: save
import git4idea.config.GitConfigUtil; //导入依赖的package包/类
public void save(@NotNull List<GitRebaseEntry> entries) throws IOException {
String encoding = GitConfigUtil.getLogEncoding(myProject, myRoot);
PrintWriter out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(myFile), encoding));
try {
for (GitRebaseEntry e : entries) {
if (e.getAction() != GitRebaseEntry.Action.skip) {
out.println(e.getAction().toString() + " " + e.getCommit() + " " + e.getSubject());
}
}
}
finally {
out.close();
}
}