Skip to content

Commit 5b59e61

Browse files
authored
Merge pull request #1644 from scala-steward-org/topic/gpg-sign-val
Use common val for gpg-sign option in GitAlg
2 parents 6c38e19 + 91f1320 commit 5b59e61

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

modules/core/src/main/scala/org/scalasteward/core/git/GitAlg.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ trait GitAlg[F[_]] {
7171
}
7272

7373
object GitAlg {
74-
val gitCmd: String = "git"
7574

7675
def create[F[_]](implicit
7776
config: Config,
@@ -81,6 +80,9 @@ object GitAlg {
8180
F: BracketThrowable[F]
8281
): GitAlg[F] =
8382
new GitAlg[F] {
83+
private val sign: String =
84+
if (config.signCommits) "--gpg-sign" else "--no-gpg-sign"
85+
8486
override def branchAuthors(repo: Repo, branch: Branch, base: Branch): F[List[String]] =
8587
workspaceAlg.repoDir(repo).flatMap { repoDir =>
8688
exec(Nel.of("log", "--pretty=format:'%an'", dotdot(base, branch)), repoDir)
@@ -108,8 +110,7 @@ object GitAlg {
108110
override def commitAll(repo: Repo, message: String): F[Commit] =
109111
for {
110112
repoDir <- workspaceAlg.repoDir(repo)
111-
sign = if (config.signCommits) List("--gpg-sign") else List("--no-gpg-sign")
112-
_ <- exec(Nel.of("commit", "--all", "-m", message) ++ sign, repoDir)
113+
_ <- exec(Nel.of("commit", "--all", sign, "-m", message), repoDir)
113114
} yield Commit()
114115

115116
override def containsChanges(repo: Repo): F[Boolean] =
@@ -163,8 +164,7 @@ object GitAlg {
163164
for {
164165
before <- latestSha1(repo, Branch.head)
165166
repoDir <- workspaceAlg.repoDir(repo)
166-
sign = if (config.signCommits) List("--gpg-sign") else List.empty
167-
_ <- exec(Nel.of("merge", "--strategy-option=theirs") ++ (sign :+ branch.name), repoDir)
167+
_ <- exec(Nel.of("merge", "--strategy-option=theirs", sign, branch.name), repoDir)
168168
.handleErrorWith { throwable =>
169169
// Resolve CONFLICT (modify/delete) by deleting unmerged files:
170170
for {
@@ -173,7 +173,7 @@ object GitAlg {
173173
case Some(files) => files.traverse(file => exec(Nel.of("rm", file), repoDir))
174174
case None => F.raiseError(throwable)
175175
}
176-
_ <- exec(Nel.of("commit", "--all", "--no-edit") ++ sign, repoDir)
176+
_ <- exec(Nel.of("commit", "--all", "--no-edit", sign), repoDir)
177177
} yield List.empty
178178
}
179179
after <- latestSha1(repo, Branch.head)
@@ -208,7 +208,7 @@ object GitAlg {
208208
_ <- push(repo, defaultBranch)
209209
} yield ()
210210

211-
def exec(command: Nel[String], cwd: File): F[List[String]] =
212-
processAlg.exec(gitCmd :: command, cwd, "GIT_ASKPASS" -> config.gitAskPass.pathAsString)
211+
private def exec(command: Nel[String], cwd: File): F[List[String]] =
212+
processAlg.exec("git" :: command, cwd, "GIT_ASKPASS" -> config.gitAskPass.pathAsString)
213213
}
214214
}

modules/core/src/test/scala/org/scalasteward/core/git/GitAlgTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class GitAlgTest extends AnyFunSuite with Matchers {
6464

6565
state shouldBe MockState.empty.copy(
6666
commands = Vector(
67-
List(askPass, repoDir, "git", "commit", "--all", "-m", "Initial commit", "--no-gpg-sign")
67+
List(askPass, repoDir, "git", "commit", "--all", "--no-gpg-sign", "-m", "Initial commit")
6868
)
6969
)
7070
}

0 commit comments

Comments
 (0)