private boolean stash() { if (!mySyncResult.hasLocalRepository()) { LOG.error("unexpected null local repro in call to stash"); return false; } final ChangeListManager changeListManager = ChangeListManager.getInstance(myProject); if (changeListManager.isFreezedWithNotification("Can not stash changes now")) return false; final GitLineHandler handler = new GitLineHandler(myProject, mySourceRepository.getRoot(), GitCommand.STASH); handler.addParameters("save"); handler.addParameters("--keep-index"); String date = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(new Date()); myStashMessage = "Cloud Debugger saved changes from branch " + myOriginalBranchName + " at " + date; handler.addParameters(myStashMessage); AccessToken token = DvcsUtil.workingTreeChangeStarted(myProject); try { GitHandlerUtil.doSynchronously( handler, GitBundle.getString("stashing.title"), handler.printableCommandLine()); } finally { DvcsUtil.workingTreeChangeFinished(myProject, token); } return true; }
/** * Checks if update is possible, saves local changes and updates all roots. In case of error shows * notification and returns false. If update completes without errors, returns true. * * <p>Perform update on all roots. 0. Blocks reloading project on external change, saving/syncing * on frame deactivation. 1. Checks if update is possible (rebase/merge in progress, no tracked * branches...) and provides merge dialog to solve problems. 2. Finds updaters to use (merge or * rebase). 3. Preserves local changes if needed (not needed for merge sometimes). 4. Updates via * 'git pull' or equivalent. 5. Restores local changes if update completed or failed with error. * If update is incomplete, i.e. some unmerged files remain, local changes are not restored. */ @NotNull public GitUpdateResult update(final UpdateMethod updateMethod) { LOG.info("update started|" + updateMethod); String oldText = myProgressIndicator.getText(); myProgressIndicator.setText("Updating..."); for (GitRepository repository : myRepositories) { repository.update(); } // check if update is possible if (checkRebaseInProgress() || isMergeInProgress() || areUnmergedFiles() || !checkTrackedBranchesConfigured()) { return GitUpdateResult.NOT_READY; } if (!fetchAndNotify()) { return GitUpdateResult.NOT_READY; } AccessToken token = DvcsUtil.workingTreeChangeStarted(myProject); GitUpdateResult result; try { result = updateImpl(updateMethod); } finally { DvcsUtil.workingTreeChangeFinished(myProject, token); } myProgressIndicator.setText(oldText); return result; }
@NotNull public String getCaption() { return "Current branch in " + DvcsUtil.getShortRepositoryName(myRepository) + ": " + getDisplayableBranchText(); }
@Nullable @Override protected HgRepository guessCurrentRepository(@NotNull Project project) { return DvcsUtil.guessCurrentRepositoryQuick( project, HgUtil.getRepositoryManager(project), HgProjectSettings.getInstance(project).getRecentRootPath()); }
@Override protected void deactivate() { if (myVFSListener != null) { Disposer.dispose(myVFSListener); myVFSListener = null; } if (myBranchWidget != null) { DvcsUtil.removeStatusBarWidget(myProject, myBranchWidget); myBranchWidget = null; } }
private String constructAmendedMessage() { Set<VirtualFile> selectedRoots = getVcsRoots(getSelectedFilePaths()); // get only selected files LinkedHashSet<String> messages = ContainerUtil.newLinkedHashSet(); if (myMessagesForRoots != null) { for (VirtualFile root : selectedRoots) { String message = myMessagesForRoots.get(root); if (message != null) { messages.add(message); } } } return DvcsUtil.joinMessagesOrNull(messages); }
/** * @param currentRepository Pass null in the case of common repositories - none repository will be * highlighted then. * @param actionsGroup * @param branchText */ public RootAction( @NotNull T repository, @Nullable T currentRepository, @NotNull ActionGroup actionsGroup, @NotNull String branchText) { super("", true); myRepository = repository; myGroup = actionsGroup; myBranchText = branchText; if (repository.equals(currentRepository)) { getTemplatePresentation().setIcon(PlatformIcons.CHECK_ICON); } getTemplatePresentation().setText(DvcsUtil.getShortRepositoryName(repository), false); }
@Override protected void activate() { checkExecutableAndVersion(); if (myVFSListener == null) { myVFSListener = new GitVFSListener(myProject, this, myGit); } ServiceManager.getService( myProject, VcsUserRegistry.class); // make sure to read the registry before opening commit dialog if (!ApplicationManager.getApplication().isHeadlessEnvironment()) { myBranchWidget = new GitBranchWidget(myProject); DvcsUtil.installStatusBarWidget(myProject, myBranchWidget); } if (myRepositoryForAnnotationsListener == null) { myRepositoryForAnnotationsListener = new GitRepositoryForAnnotationsListener(myProject); } ServiceManager.getService(myProject, GitUserRegistry.class).activate(); }
@Override public void actionPerformed(final AnActionEvent event) { final Project project = event.getProject(); assert project != null; final VirtualFile file = getAffectedFile(event); GitRepositoryManager manager = GitUtil.getRepositoryManager(project); GitRepository repository = manager.getRepositoryForFile(file); assert repository != null; GitBranch currentBranch = repository.getCurrentBranch(); final String head; if (currentBranch == null) { String currentRevision = repository.getCurrentRevision(); LOG.assertTrue( currentRevision != null, "Current revision is null for " + repository + ". Compare with branch shouldn't be available for fresh repository"); head = DvcsUtil.getShortHash(currentRevision); } else { head = currentBranch.getName(); } final List<String> branchNames = getBranchNamesExceptCurrent(repository); // prepare and invoke popup final JBList list = new JBList(branchNames); JBPopupFactory.getInstance() .createListPopupBuilder(list) .setTitle("Select branch to compare") .setItemChoosenCallback(new OnBranchChooseRunnable(project, file, head, list)) .setAutoselectOnMouseMove(true) .createPopup() .showInBestPositionFor(event.getDataContext()); }
@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); }
@Override public void actionPerformed(AnActionEvent e) { Data data = Data.collect(e); if (!data.isValid()) { return; } List<VcsFullCommitDetails> details = data.log.getSelectedDetails(); if (details.size() != 1) { return; } VcsFullCommitDetails commit = details.get(0); GitRepositoryManager repositoryManager = ServiceManager.getService(data.project, GitRepositoryManager.class); final GitRepository repository = repositoryManager.getRepositoryForRoot(commit.getRoot()); if (repository == null) { DvcsUtil.noVcsRepositoryForRoot( LOG, commit.getRoot(), data.project, repositoryManager, GitVcs.getInstance(data.project)); return; } actionPerformed(repository, commit); }
@Nullable @Override protected GitRepository guessCurrentRepository(@NotNull Project project) { return DvcsUtil.guessCurrentRepositoryQuick( project, GitUtil.getRepositoryManager(project), mySettings.getRecentRootPath()); }
/** * @return the short revision number. The revision number likely unambiguously identify local * revision, however in rare cases there could be conflicts. */ @NotNull public String getShortRev() { return DvcsUtil.getShortHash(myRevisionHash); }
boolean isValid() { return project != null && log != null && DvcsUtil.logHasRootForVcs(log, GitVcs.getKey()); }