本文整理汇总了Java中git4idea.repo.GitRepository类的典型用法代码示例。如果您正苦于以下问题:Java GitRepository类的具体用法?Java GitRepository怎么用?Java GitRepository使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GitRepository类属于git4idea.repo包,在下文中一共展示了GitRepository类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCurrentBranch
import git4idea.repo.GitRepository; //导入依赖的package包/类
public static String getCurrentBranch(@NotNull final Project project) {
GitRepository repository;
GitLocalBranch localBranch;
String branchName = "";
try {
repository = GitBranchUtil.getCurrentRepository(project);
localBranch = repository.getCurrentBranch();
branchName = localBranch.getName();
} catch (Exception e) {
e.getMessage();
}
if (branchName == null) {
branchName = "";
}
return branchName;
}
示例2: openInBrowser
import git4idea.repo.GitRepository; //导入依赖的package包/类
protected static void openInBrowser(Project project, GitRepository repository, String revisionHash) {
String url = GithubUtil.findGithubRemoteUrl(repository);
if (url == null) {
GithubUtil.LOG.info(String.format("Repository is not under GitHub. Root: %s, Remotes: %s", repository.getRoot(),
GitUtil.getPrintableRemotes(repository.getRemotes())));
return;
}
GithubFullPath userAndRepository = GithubUrlUtil.getUserAndRepositoryFromRemoteUrl(url);
if (userAndRepository == null) {
GithubNotifications
.showError(project, GithubOpenInBrowserAction.CANNOT_OPEN_IN_BROWSER, "Cannot extract info about repository: " + url);
return;
}
String githubUrl = GithubUrlUtil.getGithubHost() + '/' + userAndRepository.getUser() + '/'
+ userAndRepository.getRepository() + "/commit/" + revisionHash;
BrowserUtil.browse(githubUrl);
}
示例3: loadRefs
import git4idea.repo.GitRepository; //导入依赖的package包/类
/**
* Load tags and branches
*/
protected void loadRefs() {
try {
myLocalBranches.clear();
myRemoteBranches.clear();
myTags.clear();
final VirtualFile root = gitRoot();
GitRepository repository = GitUtil.getRepositoryManager(myProject).getRepositoryForRoot(root);
if (repository != null) {
myLocalBranches.addAll(repository.getBranches().getLocalBranches());
myRemoteBranches.addAll(repository.getBranches().getRemoteBranches());
myCurrentBranch = repository.getCurrentBranch();
}
else {
LOG.error("Repository is null for root " + root);
}
GitTag.list(myProject, root, myTags);
}
catch (VcsException e) {
GitUIUtil.showOperationError(myProject, e, "git branch -a");
}
}
示例4: cherryPick
import git4idea.repo.GitRepository; //导入依赖的package包/类
public void cherryPick(@NotNull List<VcsFullCommitDetails> commits) {
Map<GitRepository, List<VcsFullCommitDetails>> commitsInRoots =
DvcsUtil.<GitRepository>groupCommitsByRoots(myPlatformFacade.getRepositoryManager(myProject), commits);
List<GitCommitWrapper> successfulCommits = ContainerUtil.newArrayList();
List<GitCommitWrapper> alreadyPicked = ContainerUtil.newArrayList();
AccessToken token = DvcsUtil.workingTreeChangeStarted(myProject);
try {
for (Map.Entry<GitRepository, List<VcsFullCommitDetails>> entry : commitsInRoots.entrySet()) {
GitRepository repository = entry.getKey();
boolean result = cherryPick(repository, entry.getValue(), successfulCommits, alreadyPicked);
repository.update();
if (!result) {
return;
}
}
notifyResult(successfulCommits, alreadyPicked);
}
finally {
DvcsUtil.workingTreeChangeFinished(myProject, token);
}
}
示例5: readBranches
import git4idea.repo.GitRepository; //导入依赖的package包/类
@NotNull
private Set<VcsRef> readBranches(@NotNull GitRepository repository) {
StopWatch sw = StopWatch.start("readBranches in " + repository.getRoot().getName());
VirtualFile root = repository.getRoot();
repository.update();
Collection<GitLocalBranch> localBranches = repository.getBranches().getLocalBranches();
Collection<GitRemoteBranch> remoteBranches = repository.getBranches().getRemoteBranches();
Set<VcsRef> refs = new THashSet<VcsRef>(localBranches.size() + remoteBranches.size());
for (GitLocalBranch localBranch : localBranches) {
refs.add(myVcsObjectsFactory.createRef(localBranch.getHash(), localBranch.getName(), GitRefManager.LOCAL_BRANCH, root));
}
for (GitRemoteBranch remoteBranch : remoteBranches) {
refs.add(
myVcsObjectsFactory.createRef(remoteBranch.getHash(), remoteBranch.getNameForLocalOperations(), GitRefManager.REMOTE_BRANCH, root));
}
String currentRevision = repository.getCurrentRevision();
if (currentRevision != null) { // null => fresh repository
refs.add(myVcsObjectsFactory.createRef(HashImpl.build(currentRevision), "HEAD", GitRefManager.HEAD, root));
}
sw.report();
return refs;
}
示例6: stringifyBranchesByRepos
import git4idea.repo.GitRepository; //导入依赖的package包/类
@NotNull
protected static String stringifyBranchesByRepos(@NotNull Map<GitRepository, String> heads) {
MultiMap<String, VirtualFile> grouped = groupByBranches(heads);
if (grouped.size() == 1) {
return grouped.keySet().iterator().next();
}
return StringUtil.join(grouped.entrySet(), new Function<Map.Entry<String, Collection<VirtualFile>>, String>() {
@Override
public String fun(Map.Entry<String, Collection<VirtualFile>> entry) {
String roots = StringUtil.join(entry.getValue(), new Function<VirtualFile, String>() {
@Override
public String fun(VirtualFile file) {
return file.getName();
}
}, ", ");
return entry.getKey() + " (in " + roots + ")";
}
}, "<br/>");
}
示例7: GitCompareBranchesDialog
import git4idea.repo.GitRepository; //导入依赖的package包/类
public GitCompareBranchesDialog(@NotNull Project project,
@NotNull String branchName,
@NotNull String currentBranchName,
@NotNull GitCommitCompareInfo compareInfo,
@NotNull GitRepository initialRepo,
boolean dialog) {
myProject = project;
String rootString;
if (compareInfo.getRepositories().size() == 1 && GitUtil.getRepositoryManager(myProject).moreThanOneRoot()) {
rootString = " in root " + DvcsUtil.getShortRepositoryName(initialRepo);
}
else {
rootString = "";
}
myTitle = String.format("Comparing %s with %s%s", currentBranchName, branchName, rootString);
myMode = dialog ? Mode.MODAL : Mode.FRAME;
JPanel diffPanel = new GitCompareBranchesDiffPanel(myProject, branchName, currentBranchName, compareInfo);
myLogPanel = new GitCompareBranchesLogPanel(myProject, branchName, currentBranchName, compareInfo, initialRepo);
myTabbedPane = new TabbedPaneImpl(SwingConstants.TOP);
myTabbedPane.addTab("Log", VcsLogIcons.Branch, myLogPanel);
myTabbedPane.addTab("Diff", AllIcons.Actions.Diff, diffPanel);
myTabbedPane.setKeyboardNavigation(TabbedPaneImpl.DEFAULT_PREV_NEXT_SHORTCUTS);
}
示例8: getLocationFor
import git4idea.repo.GitRepository; //导入依赖的package包/类
public RepositoryLocation getLocationFor(@NotNull FilePath root) {
VirtualFile gitRoot = GitUtil.getGitRootOrNull(root);
if (gitRoot == null) {
return null;
}
GitRepository repository = GitUtil.getRepositoryManager(myProject).getRepositoryForRoot(gitRoot);
if (repository == null) {
LOG.info("No GitRepository for " + gitRoot);
return null;
}
GitLocalBranch currentBranch = repository.getCurrentBranch();
if (currentBranch == null) {
return null;
}
GitRemoteBranch trackedBranch = currentBranch.findTrackedBranch(repository);
if (trackedBranch == null) {
return null;
}
File rootFile = new File(gitRoot.getPath());
return new GitRepositoryLocation(trackedBranch.getRemote().getFirstUrl(), rootFile);
}
示例9: showUnmergedFilesNotification
import git4idea.repo.GitRepository; //导入依赖的package包/类
@Override
public void showUnmergedFilesNotification(@NotNull final String operationName, @NotNull final Collection<GitRepository> repositories) {
String title = unmergedFilesErrorTitle(operationName);
String description = unmergedFilesErrorNotificationDescription(operationName);
VcsNotifier.getInstance(myProject).notifyError(title, description,
new NotificationListener() {
@Override
public void hyperlinkUpdate(@NotNull Notification notification,
@NotNull HyperlinkEvent event) {
if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED && event.getDescription().equals("resolve")) {
GitConflictResolver.Params params = new GitConflictResolver.Params().
setMergeDescription(String.format("The following files have unresolved conflicts. You need to resolve them before %s.",
operationName)).
setErrorNotificationTitle("Unresolved files remain.");
new GitConflictResolver(myProject, myGit, myFacade, GitUtil.getRootsFromRepositories(repositories), params).merge();
}
}
}
);
}
示例10: notifyResult
import git4idea.repo.GitRepository; //导入依赖的package包/类
private void notifyResult(@NotNull Map<GitRepository, GitCommandResult> results) {
Map<GitRepository, GitCommandResult> successes = ContainerUtil.newHashMap();
Map<GitRepository, GitCommandResult> errors = ContainerUtil.newHashMap();
for (Map.Entry<GitRepository, GitCommandResult> entry : results.entrySet()) {
GitCommandResult result = entry.getValue();
GitRepository repository = entry.getKey();
if (result.success()) {
successes.put(repository, result);
}
else {
errors.put(repository, result);
}
}
if (errors.isEmpty()) {
myNotifier.notifySuccess("", "Reset successful");
}
else if (!successes.isEmpty()) {
myNotifier.notifyImportantWarning("Reset partially failed",
"Reset was successful for " + joinRepos(successes.keySet())
+ "<br/>but failed for " + joinRepos(errors.keySet()) + ": <br/>" + formErrorReport(errors));
}
else {
myNotifier.notifyError("Reset Failed", formErrorReport(errors));
}
}
示例11: test_delete_unmerged_branch_should_show_dialog
import git4idea.repo.GitRepository; //导入依赖的package包/类
public void test_delete_unmerged_branch_should_show_dialog() {
prepareUnmergedBranch(myCommunity);
final Ref<Boolean> dialogShown = Ref.create(false);
deleteBranch("todelete", new TestUiHandler() {
@Override
public boolean showBranchIsNotFullyMergedDialog(@NotNull Project project,
@NotNull Map<GitRepository, List<GitCommit>> history,
@NotNull String unmergedBranch,
@NotNull List<String> mergedToBranches,
@NotNull String baseBranch) {
dialogShown.set(true);
return false;
}
@Override
public boolean notifyErrorWithRollbackProposal(@NotNull String title, @NotNull String message, @NotNull String rollbackProposal) {
return false;
}
});
assertTrue("'Branch is not fully merged' dialog was not shown", dialogShown.get());
}
示例12: parse
import git4idea.repo.GitRepository; //导入依赖的package包/类
@NotNull
public static GitPushTarget parse(@NotNull GitRepository repository, @Nullable String remoteName, @NotNull String branchName) throws
ParseException {
if (remoteName == null) {
throw new ParseException("No remotes defined", -1);
}
if (!GitRefNameValidator.getInstance().checkInput(branchName)) {
throw new ParseException("Invalid destination branch name: " + branchName, -1);
}
GitRemote remote = findRemote(repository.getRemotes(), remoteName);
if (remote == null) {
LOG.error("Remote [" + remoteName + "] is not found among " + repository.getRemotes());
throw new ParseException("Invalid remote: " + remoteName, -1);
}
GitRemoteBranch existingRemoteBranch = findRemoteBranch(repository, remote, branchName);
if (existingRemoteBranch != null) {
return new GitPushTarget(existingRemoteBranch, false);
}
GitRemoteBranch rb = new GitStandardRemoteBranch(remote, branchName, GitBranch.DUMMY_HASH);
return new GitPushTarget(rb, true);
}
示例13: fetchCurrentRemote
import git4idea.repo.GitRepository; //导入依赖的package包/类
@NotNull
private GitFetchResult fetchCurrentRemote(@NotNull GitRepository repository) {
FetchParams fetchParams = getFetchParams(repository);
if (fetchParams.isError()) {
return fetchParams.getError();
}
GitRemote remote = fetchParams.getRemote();
return fetchRemote(repository, remote, null);
}
示例14: test_success_and_resolved_conflicts
import git4idea.repo.GitRepository; //导入依赖的package包/类
public void test_success_and_resolved_conflicts() {
GitPushResultNotification notification = notification(new HashMap<GitRepository, GitPushRepoResult>() {{
put(repo("community"), repoResult(REJECTED, "master", "origin/master", -1, GitUpdateResult.SUCCESS_WITH_RESOLVED_CONFLICTS));
put(repo("contrib"), repoResult(REJECTED, "master", "origin/master", -1, GitUpdateResult.SUCCESS_WITH_RESOLVED_CONFLICTS));
put(repo("ultimate"), repoResult(SUCCESS, "master", "origin/master", 1));
}});
assertNotification(NotificationType.WARNING, "Push partially rejected",
"ultimate: pushed 1 commit to origin/master<br/>" +
"community: " + GitPushResultNotification.UPDATE_WITH_RESOLVED_CONFLICTS + "<br/>" +
"contrib: " + GitPushResultNotification.UPDATE_WITH_RESOLVED_CONFLICTS + "<br/>" +
GitPushResultNotification.VIEW_FILES_UPDATED_DURING_THE_PUSH, notification);
}
示例15: execute
import git4idea.repo.GitRepository; //导入依赖的package包/类
@Override
protected void execute() {
boolean fatalErrorHappened = false;
while (hasMoreRepositories() && !fatalErrorHappened) {
final GitRepository repository = next();
GitSimpleEventDetector unmergedDetector = new GitSimpleEventDetector(GitSimpleEventDetector.Event.UNMERGED_PREVENTING_CHECKOUT);
GitCommandResult result = myGit.checkoutNewBranch(repository, myNewBranchName, unmergedDetector);
if (result.success()) {
refresh(repository);
markSuccessful(repository);
}
else if (unmergedDetector.hasHappened()) {
fatalUnmergedFilesError();
fatalErrorHappened = true;
}
else {
fatalError("Couldn't create new branch " + myNewBranchName, result.getErrorOutputAsJoinedString());
fatalErrorHappened = true;
}
}
if (!fatalErrorHappened) {
notifySuccess();
updateRecentBranch();
}
}