void () { final String message = myMessageTextArea.getText(); final boolean hasMessage = message.trim().length() != 0; final File messageFile; if (hasMessage) { try { messageFile = FileUtil.createTempFile(MESSAGE_FILE_PREFIX, MESSAGE_FILE_SUFFIX); messageFile.deleteOnExit(); try (Writer out = new OutputStreamWriter(new FileOutputStream(messageFile), MESSAGE_FILE_ENCODING)) { out.write(message); } } catch (IOException ex) { myNotifier.notifyError(TAG_NOT_CREATED, GitBundle.message("git.tag.could.not.create.tag"), GitBundle.message("tag.error.creating.message.file.message", ex.toString()) ); return; } } else { messageFile = null; } try { GitLineHandler h = new GitLineHandler(myProject, getGitRoot(), GitCommand.TAG); if (hasMessage) { h.addParameters("-a"); } if (myForceCheckBox.isEnabled() && myForceCheckBox.isSelected()) { h.addParameters("-f"); } if (hasMessage) { h.addParameters("-F"); h.addAbsoluteFile(messageFile); } h.addParameters(myTagNameTextField.getText()); String object = myCommitTextField.getText().trim(); if (object.length() != 0) { h.addParameters(object); } GitCommandResult result = myGit.runCommand(h); if (result.success()) { myNotifier.notifySuccess(TAG_CREATED, myTagNameTextField.getText(), GitBundle.message("git.tag.created.tag.successfully", myTagNameTextField.getText()) ); } else { myNotifier.notifyError(TAG_NOT_CREATED, GitBundle.message("git.tag.could.not.create.tag"), result.getErrorOutputAsHtmlString(), true); } GitRepository repository = GitUtil.getRepositoryManager(myProject).getRepositoryForRoot(getGitRoot()); if (repository != null) { repository.getRepositoryFiles().refreshTagsFiles(); } else { LOG.error("No repository registered for root: " + getGitRoot()); } } finally { if (messageFile != null) { //noinspection ResultOfMethodCallIgnored messageFile.delete(); } } }