New command: "Reset To"
Add a new command that allows to reset the current branch to the commit
that was fetched. This is useful in cases when the user is working on a
local branch and the existing commands are not appropriate:
- "Checkout" will check out the FETCH_HEAD, i.e. moving off the current
branch and leaving the local repository in 'detached head' state.
- "Cherry-Pick" will commit the fetched change again, resulting in a
'new' commit (i.e. changed sha1) which will result in a new patch set
if the user creates any commits on top of it and pushes for review.
Change-Id: I683f88aa0d8ad6a6dd91f341bd23d363d329e174
diff --git a/src/main/java/com/googlesource/gerrit/plugins/download/command/DownloadCommandsModule.java b/src/main/java/com/googlesource/gerrit/plugins/download/command/DownloadCommandsModule.java
index 2f64b71..0e5f11b 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/download/command/DownloadCommandsModule.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/download/command/DownloadCommandsModule.java
@@ -25,6 +25,8 @@
bind(DownloadCommand.class).annotatedWith(Exports.named("Branch")).to(BranchCommand.class);
+ bind(DownloadCommand.class).annotatedWith(Exports.named("Reset To")).to(ResetCommand.class);
+
bind(DownloadCommand.class)
.annotatedWith(Exports.named("Cherry Pick"))
.to(CherryPickCommand.class);
diff --git a/src/main/java/com/googlesource/gerrit/plugins/download/command/ResetCommand.java b/src/main/java/com/googlesource/gerrit/plugins/download/command/ResetCommand.java
new file mode 100644
index 0000000..8309f89
--- /dev/null
+++ b/src/main/java/com/googlesource/gerrit/plugins/download/command/ResetCommand.java
@@ -0,0 +1,38 @@
+// Copyright (C) 2020 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.googlesource.gerrit.plugins.download.command;
+
+import static com.google.gerrit.extensions.client.GeneralPreferencesInfo.DownloadCommand.CHECKOUT;
+
+import com.google.gerrit.server.config.DownloadConfig;
+import com.google.gerrit.server.config.GerritServerConfig;
+import com.google.gerrit.server.git.GitRepositoryManager;
+import com.google.inject.Inject;
+import org.eclipse.jgit.lib.Config;
+
+public class ResetCommand extends GitDownloadCommand {
+ @Inject
+ ResetCommand(
+ @GerritServerConfig Config cfg,
+ DownloadConfig downloadConfig,
+ GitRepositoryManager repoManager) {
+ super(cfg, downloadConfig, CHECKOUT, repoManager);
+ }
+
+ @Override
+ String getCommand(String url, String ref, String id) {
+ return "git fetch " + QuoteUtil.quote(url) + " " + ref + " && git reset --hard FETCH_HEAD";
+ }
+}