Skip to content

Commit c7ce825

Browse files
committed
Fix #11 by asserting the git result that we expect.
1 parent 107f7d6 commit c7ce825

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88
### Fixed
9-
- Bug in `PoolString.concat(String)`.
9+
- Better error message for cases where the `spotlessChangelog` block is too low. ([#6](https://github.com/diffplug/spotless-changelog/issues/6))
10+
- Bug in `PoolString.concat(String)` ([1f6da65](https://github.com/diffplug/spotless-changelog/commit/1f6da65b51c5ee7af847dc0e427fe685fbd3d43c)).
11+
- No longer accepts git failures silently (they were always printed, but did not properly kill the build). ([#11](https://github.com/diffplug/spotless-changelog/issues/11))
1012

1113
## [1.1.0] - 2020-01-13
1214
### Added

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ We publish tagged releases to mavenCentral, jcenter, and the gradle plugin porta
4242

4343
## License
4444

45-
By contributing your code, you agree to license your contribution under the terms of the APLv2: https://github.com/diffplug/blowdryer/blob/master/LICENSE
45+
By contributing your code, you agree to license your contribution under the terms of the APLv2: https://github.com/diffplug/spotless-changelog/blob/main/LICENSE
4646

4747
All files are released with the Apache 2.0 license as such:
4848

4949
```
50-
Copyright 2019 DiffPlug
50+
Copyright (C) 2019-2020 DiffPlug
5151
5252
Licensed under the Apache License, Version 2.0 (the "License");
5353
you may not use this file except in compliance with the License.

spotless-changelog-lib/src/main/java/com/diffplug/spotless/changelog/GitActions.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.Arrays;
2323
import java.util.List;
2424
import java.util.Objects;
25+
import java.util.Optional;
2526
import java.util.function.Consumer;
2627
import org.eclipse.jgit.api.Git;
2728
import org.eclipse.jgit.api.PushCommand;
@@ -66,7 +67,7 @@ public void checkCanPush() throws GitAPIException, IOException {
6667
if (!ref.getObjectId().equals(remoteRef.getObjectId())) {
6768
throw new IllegalStateException("Local branch " + cfg.branch + " is out of sync with " + cfg.remote + ", so we can't safely push it automatically.");
6869
}
69-
push(cfg.branch);
70+
push(cfg.branch, RemoteRefUpdate.Status.UP_TO_DATE);
7071
} catch (GitAPIException e) {
7172
throw new IllegalArgumentException("You can set user/pass with any of these environment variables: " + envVars(), e);
7273
}
@@ -95,8 +96,8 @@ public void addAndCommit() throws GitAPIException {
9596
/** Tags and pushes the tag and the branch. */
9697
public void tagBranchPush() throws GitAPIException {
9798
Ref tagRef = git.tag().setName(tagName()).setAnnotated(false).call();
98-
push(tagRef);
99-
push(cfg.branch);
99+
push(tagRef, RemoteRefUpdate.Status.OK);
100+
push(cfg.branch, RemoteRefUpdate.Status.OK);
100101
}
101102

102103
private String tagName() {
@@ -108,15 +109,15 @@ public void close() {
108109
repository.close();
109110
}
110111

111-
private void push(String branch) throws GitAPIException {
112-
push(cmd -> cmd.add(branch));
112+
private void push(String branch, RemoteRefUpdate.Status expected) throws GitAPIException {
113+
push(cmd -> cmd.add(branch), expected);
113114
}
114115

115-
private void push(Ref ref) throws GitAPIException {
116-
push(cmd -> cmd.add(ref));
116+
private void push(Ref ref, RemoteRefUpdate.Status expected) throws GitAPIException {
117+
push(cmd -> cmd.add(ref), expected);
117118
}
118119

119-
private void push(Consumer<PushCommand> cmd) throws GitAPIException {
120+
private void push(Consumer<PushCommand> cmd, RemoteRefUpdate.Status expected) throws GitAPIException {
120121
PushCommand push = git.push().setCredentialsProvider(creds()).setRemote(cfg.remote);
121122
cmd.accept(push);
122123

@@ -132,8 +133,14 @@ private void push(Consumer<PushCommand> cmd) throws GitAPIException {
132133
+ "..."
133134
+ (update.getNewObjectId() != null ? update.getNewObjectId().name() : "(null)")
134135
+ (update.isFastForward() ? " fastForward" : "")
135-
+ (update.getMessage() != null ? " " + update.getMessage() : ""));
136-
136+
+ (update.getMessage() != null ? update.getMessage() : ""));
137+
Optional<RemoteRefUpdate.Status> failure = result.getRemoteUpdates().stream()
138+
.map(RemoteRefUpdate::getStatus)
139+
.filter(r -> !expected.equals(r))
140+
.findAny();
141+
if (failure.isPresent()) {
142+
throw new IllegalStateException("Error! Expected " + expected + ", got " + failure.get() + ".");
143+
}
137144
}
138145

139146
// similar to https://github.com/ajoberstar/grgit/blob/5766317fbe67ec39faa4632e2b80c2b056f5c124/grgit-core/src/main/groovy/org/ajoberstar/grgit/auth/AuthConfig.groovy

0 commit comments

Comments
 (0)