This is an automated email from the ASF dual-hosted git repository. matthiasblaesing pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/master by this push: new 7d17072 [NETBEANS-3929] Add option to gitclient to push tag deletes 7d17072 is described below commit 7d17072e22ca45228e57ef2399ecfd7ac37c53e2 Author: Dmitry Mochalov <rigthco...@gmail.com> AuthorDate: Sun Mar 1 19:27:49 2020 +0300 [NETBEANS-3929] Add option to gitclient to push tag deletes Adding the ability to delete a tag from a remote repository using integrated GitClient. Before a user could delete a branch but could not delete a tag. Now, when performing git push... a user can select locally deleted tag and GitClient will perform git push :refs/tags/{tag_name_to_delete} --- .../netbeans/modules/git/ui/push/PushAction.java | 25 +++++++++--- .../modules/git/ui/push/PushBranchesStep.java | 24 ++++++++++- .../netbeans/modules/git/ui/push/PushMapping.java | 46 ++++++++++++++++++++-- .../org/netbeans/modules/git/utils/GitUtils.java | 5 +++ .../org/netbeans/libs/git/GitClassFactoryImpl.java | 4 +- .../org/netbeans/libs/git/GitTransportUpdate.java | 19 +++++++-- .../netbeans/libs/git/jgit/GitClassFactory.java | 2 +- .../libs/git/jgit/commands/PushCommand.java | 3 +- 8 files changed, 110 insertions(+), 18 deletions(-) diff --git a/ide/git/src/org/netbeans/modules/git/ui/push/PushAction.java b/ide/git/src/org/netbeans/modules/git/ui/push/PushAction.java index 0facca4..03302a8 100644 --- a/ide/git/src/org/netbeans/modules/git/ui/push/PushAction.java +++ b/ide/git/src/org/netbeans/modules/git/ui/push/PushAction.java @@ -159,8 +159,11 @@ public class PushAction extends SingleRepositoryAction { "# {0} - branch name", "MSG_PushAction.branchDeleted=Branch {0} deleted in the local repository.", "# {0} - branch name", "# {1} - branch head id", "# {2} - result of the update", "MSG_PushAction.updates.deleteBranch=Branch Delete : {0}\n" - + "Id : {1}\n" - + "Result : {2}\n", + + "Id : {1}\n" + + "Result : {2}\n", + "MSG_PushAction.updates.deleteTag=Tag Delete : {0}\n" + + "Id : {1}\n" + + "Result : {2}\n", "# {0} - branch name", "# {1} - branch head id", "# {2} - result of the update", "MSG_PushAction.updates.addBranch=Branch Add : {0}\n" + "Id : {1}\n" @@ -341,10 +344,20 @@ public class PushAction extends SingleRepositoryAction { } } } else { - logger.outputLine(NbBundle.getMessage(PushAction.class, "MSG_PushAction.updates.updateTag", new Object[] { //NOI18N - update.getLocalName(), - update.getResult(), - })); + //tag deleting or updating + if (update.getNewObjectId() == null && update.getOldObjectId() != null) { + //deleting tag from remote + logger.outputLine(NbBundle.getMessage(PushAction.class, "MSG_PushAction.updates.deleteTag", new Object[]{ //NOI18N + update.getRemoteName(), + update.getOldObjectId(), + update.getResult(),})); + } else { + //updating or adding tag to the remote + logger.outputLine(NbBundle.getMessage(PushAction.class, "MSG_PushAction.updates.updateTag", new Object[]{ //NOI18N + update.getLocalName(), + update.getResult(),})); + } + } } } diff --git a/ide/git/src/org/netbeans/modules/git/ui/push/PushBranchesStep.java b/ide/git/src/org/netbeans/modules/git/ui/push/PushBranchesStep.java index 63722b6..42c0320 100644 --- a/ide/git/src/org/netbeans/modules/git/ui/push/PushBranchesStep.java +++ b/ide/git/src/org/netbeans/modules/git/ui/push/PushBranchesStep.java @@ -98,6 +98,12 @@ public class PushBranchesStep extends AbstractWizardPanel implements WizardDescr return new HelpCtx(PushBranchesStep.class); } + /** + * + * @param cfg configuration of the remote repository including URLs of remote + * @param branches list of all branches in the remote repo + * @param tags list of all tags in the remote repo + */ public void fillRemoteBranches (final GitRemoteConfig cfg, final Map<String, GitBranch> branches, final Map<String, String> tags) { fillLocalObjects(Collections.<PushMapping>emptyList()); @@ -124,6 +130,7 @@ public class PushBranchesStep extends AbstractWizardPanel implements WizardDescr continue; } if (!branch.isRemote()) { + //get the remote branch that corresponds to local branch GitBranch remoteBranch = branches.get(branch.getName()); boolean conflicted = false; boolean updateNeeded = remoteBranch != null && !remoteBranch.getId().equals(branch.getId()); @@ -154,6 +161,8 @@ public class PushBranchesStep extends AbstractWizardPanel implements WizardDescr } } boolean preselected = !conflicted && updateNeeded; + + //add current branch in the list for update or for adding l.add(new PushMapping.PushBranchMapping(remoteBranch == null ? null : remoteBranch.getName(), remoteBranch == null ? null : remoteBranch.getId(), branch, conflicted, preselected, updateNeeded)); @@ -170,13 +179,26 @@ public class PushBranchesStep extends AbstractWizardPanel implements WizardDescr } } } - + + //adding a new tag for (GitTag tag : localTags.values()) { String repoTagId = tags.get(tag.getTagName()); if (!tag.getTagId().equals(repoTagId)) { + //in the remote there is no such tag, need to add it. l.add(new PushMapping.PushTagMapping(tag, repoTagId == null ? null : tag.getTagName())); } } + + //deletion of a tag + for (String tag : tags.keySet()) { + //get the name of a corresponding local tag. + GitTag localTag = localTags.get(tag); + if (localTag == null) { + //in the local repo no such tag. Probably we need to delete in the remote? + l.add(new PushMapping.PushTagMapping(tag)); + } + } + EventQueue.invokeLater(new Runnable () { @Override public void run () { diff --git a/ide/git/src/org/netbeans/modules/git/ui/push/PushMapping.java b/ide/git/src/org/netbeans/modules/git/ui/push/PushMapping.java index 5b7445d..ebdbedf 100644 --- a/ide/git/src/org/netbeans/modules/git/ui/push/PushMapping.java +++ b/ide/git/src/org/netbeans/modules/git/ui/push/PushMapping.java @@ -224,18 +224,56 @@ public abstract class PushMapping extends ItemSelector.Item { } public static final class PushTagMapping extends PushMapping { - private final GitTag tag; + private final GitTag tag; //local tag private final boolean isUpdate; - + private final String remoteTagName; + + /** + * Tag that we need to delete in the remote repository + * + * @param remoteName remote tag name + */ + public PushTagMapping(String remoteName) { + super(null, null, remoteName, false, false, remoteName != null); + this.tag = null; + this.isUpdate = remoteName != null; + this.remoteTagName = remoteName; + } + + /** + * Adding or updating tag in the remote repository + * + * @param tag representation of a local tag + * @param remoteName remote tag name, can be null. If null than we create tag. + */ public PushTagMapping (GitTag tag, String remoteName) { super("tags/" + tag.getTagName(), tag.getTaggedObjectId(), remoteName, false, false, remoteName != null); //NOI18N this.tag = tag; this.isUpdate = remoteName != null; + this.remoteTagName = remoteName; } @Override - public String getRefSpec () { - return GitUtils.getPushTagRefSpec(tag.getTagName(), isUpdate); + public String getRefSpec() { + if (isDeletion()) { + //get command for tag deletion + return GitUtils.getPushDeletedTagRefSpec(remoteTagName); + } else { + return GitUtils.getPushTagRefSpec(tag.getTagName(), isUpdate); + } + } + + @Override + @NbBundle.Messages({ + "# {0} - tag name", + "MSG_PushMapping.toBeDeletedTag=Tag {0} will be permanently removed from the remote repository." + }) + String getInfoMessage() { + if (isDeletion()) { + return Bundle.MSG_PushMapping_toBeDeletedTag(remoteTagName); + } else { + return super.getInfoMessage(); + } } @Override diff --git a/ide/git/src/org/netbeans/modules/git/utils/GitUtils.java b/ide/git/src/org/netbeans/modules/git/utils/GitUtils.java index 33742e1..e2a4b50 100644 --- a/ide/git/src/org/netbeans/modules/git/utils/GitUtils.java +++ b/ide/git/src/org/netbeans/modules/git/utils/GitUtils.java @@ -836,6 +836,7 @@ public final class GitUtils { public static final String REF_SPEC_DEL_PREFIX = ":refs/remotes/"; //NOI18N private static final String REF_PUSHSPEC_PATTERN = "refs/heads/{0}:refs/heads/{1}"; //NOI18N public static final String REF_PUSHSPEC_DEL_PREFIX = ":refs/heads/"; //NOI18N + public static final String REF_PUSHSPEC_DEL_TAG_PREFIX = ":refs/tags/"; //NOI18N private static final String REF_TAG_PUSHSPEC_PATTERN = "refs/tags/{0}:refs/tags/{0}"; //NOI18N private static final String REF_TAG_PUSHSPEC_PATTERN_FORCE = "+" + REF_TAG_PUSHSPEC_PATTERN; //NOI18N @@ -863,6 +864,10 @@ public final class GitUtils { return REF_PUSHSPEC_DEL_PREFIX + remoteRepositoryBranchName; } + public static String getPushDeletedTagRefSpec(String remoteRepositoryBranchName) { + return REF_PUSHSPEC_DEL_TAG_PREFIX + remoteRepositoryBranchName; + } + public static String getPushTagRefSpec (String tagName, boolean forceUpdate) { return MessageFormat.format(forceUpdate ? REF_TAG_PUSHSPEC_PATTERN_FORCE diff --git a/ide/libs.git/src/org/netbeans/libs/git/GitClassFactoryImpl.java b/ide/libs.git/src/org/netbeans/libs/git/GitClassFactoryImpl.java index 3a43e7f..1f88eba 100644 --- a/ide/libs.git/src/org/netbeans/libs/git/GitClassFactoryImpl.java +++ b/ide/libs.git/src/org/netbeans/libs/git/GitClassFactoryImpl.java @@ -148,8 +148,8 @@ final class GitClassFactoryImpl extends GitClassFactory { } @Override - public GitTransportUpdate createTransportUpdate (URIish urI, RemoteRefUpdate update, Map<String, GitBranch> remoteBranches) { - return new GitTransportUpdate(urI, update, remoteBranches); + public GitTransportUpdate createTransportUpdate(URIish urI, RemoteRefUpdate update, Map<String, GitBranch> remoteBranches, Map<String, String> remoteTags) { + return new GitTransportUpdate(urI, update, remoteBranches, remoteTags); } @Override diff --git a/ide/libs.git/src/org/netbeans/libs/git/GitTransportUpdate.java b/ide/libs.git/src/org/netbeans/libs/git/GitTransportUpdate.java index 1786c92..85dc998 100644 --- a/ide/libs.git/src/org/netbeans/libs/git/GitTransportUpdate.java +++ b/ide/libs.git/src/org/netbeans/libs/git/GitTransportUpdate.java @@ -74,14 +74,27 @@ public final class GitTransportUpdate { this.type = getType(update.getLocalName()); } - GitTransportUpdate (URIish uri, RemoteRefUpdate update, Map<String, GitBranch> remoteBranches) { + /** + * + * @param uri uri of the repo. + * @param update + * @param remoteBranches key value list of remote branches. + * @param remoteTags key value list of remote tags. Key - name of the tag, value - id (hash) of the tag. + */ + GitTransportUpdate(URIish uri, RemoteRefUpdate update, Map<String, GitBranch> remoteBranches, Map<String, String> remoteTags) { this.localName = stripRefs(update.getSrcRef()); this.remoteName = stripRefs(update.getRemoteName()); - this.oldObjectId = getOldRevisionId(remoteBranches.get(remoteName)); + this.type = getType(update.getRemoteName()); + if (type == type.TAG) { + //get object id for deleted tag. + this.oldObjectId = remoteTags.get(remoteName); + } else { + this.oldObjectId = getOldRevisionId(remoteBranches.get(remoteName)); + } + this.newObjectId = update.getNewObjectId() == null || ObjectId.zeroId().equals(update.getNewObjectId()) ? null : update.getNewObjectId().getName(); this.result = GitRefUpdateResult.valueOf(update.getStatus().name()); this.uri = uri.toString(); - this.type = getType(update.getRemoteName()); } /** diff --git a/ide/libs.git/src/org/netbeans/libs/git/jgit/GitClassFactory.java b/ide/libs.git/src/org/netbeans/libs/git/jgit/GitClassFactory.java index 142ab60..2be0b61 100644 --- a/ide/libs.git/src/org/netbeans/libs/git/jgit/GitClassFactory.java +++ b/ide/libs.git/src/org/netbeans/libs/git/jgit/GitClassFactory.java @@ -109,7 +109,7 @@ public abstract class GitClassFactory { public abstract GitTransportUpdate createTransportUpdate (URIish urI, TrackingRefUpdate update); - public abstract GitTransportUpdate createTransportUpdate (URIish urI, RemoteRefUpdate update, Map<String, GitBranch> remoteBranches); + public abstract GitTransportUpdate createTransportUpdate(URIish urI, RemoteRefUpdate update, Map<String, GitBranch> remoteBranches, Map<String, String> remoteTags); public abstract GitUser createUser (PersonIdent personIdent); diff --git a/ide/libs.git/src/org/netbeans/libs/git/jgit/commands/PushCommand.java b/ide/libs.git/src/org/netbeans/libs/git/jgit/commands/PushCommand.java index b975889..c73a823 100644 --- a/ide/libs.git/src/org/netbeans/libs/git/jgit/commands/PushCommand.java +++ b/ide/libs.git/src/org/netbeans/libs/git/jgit/commands/PushCommand.java @@ -96,10 +96,11 @@ public class PushCommand extends TransportCommand { transport.setTagOpt(TagOpt.AUTO_FOLLOW); PushResult pushResult = transport.push(new DelegatingProgressMonitor(monitor), fetchSpecs.isEmpty() ? transport.findRemoteRefUpdatesFor(specs) : Transport.findRemoteRefUpdatesFor(getRepository(), specs, fetchSpecs)); Map<String, GitBranch> remoteBranches = Utils.refsToBranches(pushResult.getAdvertisedRefs(), Constants.R_HEADS, getClassFactory()); + Map<String, String> remoteTags = Utils.refsToTags(pushResult.getAdvertisedRefs()); processMessages(pushResult.getMessages()); Map<String, GitTransportUpdate> remoteRepositoryUpdates = new HashMap<String, GitTransportUpdate>(pushResult.getRemoteUpdates().size()); for (RemoteRefUpdate update : pushResult.getRemoteUpdates()) { - GitTransportUpdate upd = getClassFactory().createTransportUpdate(transport.getURI(), update, remoteBranches); + GitTransportUpdate upd = getClassFactory().createTransportUpdate(transport.getURI(), update, remoteBranches, remoteTags); remoteRepositoryUpdates.put(upd.getRemoteName(), upd); } Map<String, GitTransportUpdate> localRepositoryUpdates = new HashMap<String, GitTransportUpdate>(pushResult.getTrackingRefUpdates().size()); --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org For additional commands, e-mail: commits-h...@netbeans.apache.org For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists