Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit 4f6c60f

Browse files
committed
Transform broken repo error message to be more helpful (#1251)
(cherry picked from commit 0396bf9) Signed-off-by: Harsh Shandilya <[email protected]>
1 parent 96b51e7 commit 4f6c60f

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file.
77
### Added
88

99
- Invalid `.gpg-id` files can now be fixed automatically by deleting them and then trying to create a new password.
10+
- Suggest users to re-clone repository when it is deemed to be broken
1011

1112
### Fixed
1213

app/src/main/java/com/zeapo/pwdstore/git/BaseGitActivity.kt

+26-13
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,7 @@ abstract class BaseGitActivity : ContinuationContainerActivity() {
7070
GitOp.BREAK_OUT_OF_DETACHED -> BreakOutOfDetached(this)
7171
GitOp.RESET -> ResetToRemoteOperation(this)
7272
}
73-
return op.executeAfterAuthentication(GitSettings.authMode).mapError { throwable ->
74-
val err = rootCauseException(throwable)
75-
if (err.message?.contains("cannot open additional channels") == true) {
76-
GitSettings.useMultiplexing = false
77-
SSHException(DisconnectReason.TOO_MANY_CONNECTIONS, "The server does not support multiple Git operations per SSH session. Please try again, a slower fallback mode will be used.")
78-
} else if (err is TransportException && err.disconnectReason == DisconnectReason.HOST_KEY_NOT_VERIFIABLE) {
79-
SSHException(DisconnectReason.HOST_KEY_NOT_VERIFIABLE,
80-
"WARNING: The remote host key has changed. If this is expected, please go to Git server settings and clear the saved host key."
81-
)
82-
} else {
83-
err
84-
}
85-
}
73+
return op.executeAfterAuthentication(GitSettings.authMode).mapError(::transformGitError)
8674
}
8775

8876
fun finishOnSuccessHandler(@Suppress("UNUSED_PARAMETER") nothing: Unit) {
@@ -113,6 +101,31 @@ abstract class BaseGitActivity : ContinuationContainerActivity() {
113101
}
114102
}
115103

104+
/**
105+
* Takes the result of [launchGitOperation] and applies any necessary transformations
106+
* on the [throwable] returned from it
107+
*/
108+
private fun transformGitError(throwable: Throwable): Throwable {
109+
val err = rootCauseException(throwable)
110+
return when {
111+
err.message?.contains("cannot open additional channels") == true -> {
112+
GitSettings.useMultiplexing = false
113+
SSHException(DisconnectReason.TOO_MANY_CONNECTIONS, "The server does not support multiple Git operations per SSH session. Please try again, a slower fallback mode will be used.")
114+
}
115+
err.message?.contains("int org.eclipse.jgit.lib.AnyObjectId.w1") == true -> {
116+
IllegalStateException("Your local repository appears to be an incomplete Git clone, please delete and re-clone from settings")
117+
}
118+
err is TransportException && err.disconnectReason == DisconnectReason.HOST_KEY_NOT_VERIFIABLE -> {
119+
SSHException(DisconnectReason.HOST_KEY_NOT_VERIFIABLE,
120+
"WARNING: The remote host key has changed. If this is expected, please go to Git server settings and clear the saved host key."
121+
)
122+
}
123+
else -> {
124+
err
125+
}
126+
}
127+
}
128+
116129
/**
117130
* Check if a given [Throwable] is the result of an error caused by the user cancelling the
118131
* operation.

0 commit comments

Comments
 (0)