Skip to content

Commit 78ff84e

Browse files
committed
fixed #36: add gis force push
1 parent a953ad9 commit 78ff84e

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>org.nqm</groupId>
66
<artifactId>gis</artifactId>
7-
<version>1.0.0</version>
7+
<version>1.0.1</version>
88
<packaging>${packaging}</packaging>
99

1010
<properties>

src/main/java/org/nqm/Gis.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
name = "gis",
1212
description = "Git extension wrapper which supports submodules",
1313
mixinStandardHelpOptions = true,
14-
version = "1.0.0")
14+
version = "1.0.1")
1515
public class Gis extends GitCommand {
1616

1717
@Option(names = "-v", description = "Show more details information.", scope = ScopeType.INHERIT)

src/main/java/org/nqm/command/GitCommand.java

+8-5
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,6 @@ void checkoutNewBranch(@Parameters(index = "0", paramLabel = "<new_branch_name>"
8888
}
8989
}
9090

91-
private static Stream<String> streamOf(String[] input) {
92-
return Stream.of(input).map(String::trim).distinct();
93-
}
94-
9591
@Command(name = "remove-branch", aliases = "rm")
9692
void removeBranch(@Parameters(index = "0", paramLabel = "<branch name>") String branch) {
9793
if (isConfirmed("Are you sure you want to remove branch '%s' ? [Y/n]".formatted(branch))) {
@@ -101,17 +97,24 @@ void removeBranch(@Parameters(index = "0", paramLabel = "<branch name>") String
10197

10298
@Command(name = "push", aliases = "pus")
10399
void push(@Parameters(index = "0", paramLabel = "<branch name>") String branch,
100+
@Option(names = "-f", description = "force to update remote origin branch") boolean force,
104101
@Option(names = "-r", description = "push to remote origin branch") boolean newRemoteBranch) {
105102

106103
if (!isConfirmed("Are you sure you want to push to remote '%s' [Y/n]".formatted(branch))) {
107104
return;
108105
}
109-
var args = newRemoteBranch ? new String[] { "push", "-u", "origin", branch } : new String[] { "push" };
106+
var args = newRemoteBranch
107+
? new String[] { "push", "-u", "origin", branch }
108+
: force ? new String[] { "push", "-f" } : new String[] { "push" };
110109
forEachModuleWith(
111110
path -> isSameBranchUnderPath(branch, path),
112111
path -> deployVertx(path, args));
113112
}
114113

114+
private static Stream<String> streamOf(String[] input) {
115+
return Stream.of(input).map(String::trim).distinct();
116+
}
117+
115118
private boolean isSameBranchUnderPath(String branch, Path path) {
116119
try {
117120
var proc = new ProcessBuilder(GisConfig.GIT_HOME_DIR, "branch", "--show-current")

0 commit comments

Comments
 (0)