Skip to content

Commit 6798553

Browse files
author
Devon Stewart
committed
Adding GitAlg.diff
1 parent 21c5160 commit 6798553

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ final class FileGitAlg[F[_]](config: GitCfg)(implicit
138138
override def version: F[String] =
139139
workspaceAlg.rootDir.flatMap(git("--version")).map(_.mkString.trim)
140140

141+
override def diff(repo: File, branch: Branch): F[List[String]] =
142+
git("diff", branch.name)(repo)
143+
141144
private def git(args: String*)(repo: File): F[List[String]] =
142145
processAlg.exec(Nel.of("git", args: _*), repo, "GIT_ASKPASS" -> config.gitAskPass.pathAsString)
143146

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ trait GenGitAlg[F[_], Repo] {
6969

7070
def version: F[String]
7171

72+
def diff(repo: Repo, branch: Branch): F[List[String]]
73+
7274
final def commitAllIfDirty(repo: Repo, message: String, messages: String*)(implicit
7375
F: Monad[F]
7476
): F[Option[Commit]] =
@@ -142,6 +144,9 @@ trait GenGitAlg[F[_], Repo] {
142144

143145
override def version: F[String] =
144146
self.version
147+
148+
override def diff(repo: A, branch: Branch): F[List[String]] =
149+
f(repo).flatMap(self.diff(_, branch))
145150
}
146151
}
147152
}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,23 @@ class FileGitAlgTest extends FunSuite {
143143
test("version") {
144144
assert(ioGitAlg.version.unsafeRunSync().nonEmpty)
145145
}
146+
147+
test("diff") {
148+
val repo = rootDir / "diff"
149+
val wip = Branch("wip")
150+
val p = for {
151+
_ <- supplement.createRepo(repo)
152+
_ <- ioFileAlg.writeFile(repo / "test.txt", "hello")
153+
_ <- supplement.git("add", "test.txt")(repo)
154+
_ <- ioGitAlg.commitAll(repo, "Add test.txt")
155+
// work on wip
156+
_ <- ioGitAlg.createBranch(repo, wip)
157+
c1 <- ioGitAlg.diff(repo, master)
158+
_ <- ioFileAlg.writeFile(repo / "test.txt", "hello world")
159+
c2 <- ioGitAlg.diff(repo, master)
160+
} yield (c1.isEmpty, c2.isEmpty)
161+
assertEquals(p.unsafeRunSync(), (true, false))
162+
}
146163
}
147164

148165
object FileGitAlgTest {

0 commit comments

Comments
 (0)