File tree Expand file tree Collapse file tree 4 files changed +44
-2
lines changed
main/scala/org/scalasteward/core
test/scala/org/scalasteward/core/git Expand file tree Collapse file tree 4 files changed +44
-2
lines changed Original file line number Diff line number Diff line change @@ -95,7 +95,13 @@ final class HookExecutor[F[_]](implicit
95
95
oldContent <- fileAlg.readFile(file)
96
96
newContent = oldContent.fold(newLines)(_ + " \n " + newLines)
97
97
_ <- fileAlg.writeFile(file, newContent)
98
- _ <- gitAlg.add(repo, file.pathAsString)
98
+ pathAsString = file.pathAsString
99
+ _ <- gitAlg
100
+ .checkIgnore(repo, pathAsString)
101
+ .ifM(
102
+ logger.warn(s " Impossible to add ' $pathAsString' because it is git ignored. " ),
103
+ gitAlg.add(repo, pathAsString)
104
+ )
99
105
blameIgnoreCommitMsg = CommitMsg (s " Add ' ${commitMsg.title}' to $gitBlameIgnoreRevsName" )
100
106
maybeBlameIgnoreCommit <- gitAlg.commitAllIfDirty(repo, blameIgnoreCommitMsg)
101
107
} yield maybeBlameIgnoreCommit
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ import cats.syntax.all._
22
22
import org .http4s .Uri
23
23
import org .scalasteward .core .application .Config .GitCfg
24
24
import org .scalasteward .core .git .FileGitAlg .{dotdot , gitCmd }
25
- import org .scalasteward .core .io .process .SlurpOptions
25
+ import org .scalasteward .core .io .process .{ ProcessFailedException , SlurpOptions }
26
26
import org .scalasteward .core .io .{FileAlg , ProcessAlg , WorkspaceAlg }
27
27
import org .scalasteward .core .util .Nel
28
28
@@ -47,6 +47,11 @@ final class FileGitAlg[F[_]](config: GitCfg)(implicit
47
47
override def checkoutBranch (repo : File , branch : Branch ): F [Unit ] =
48
48
git_(" checkout" , branch.name)(repo).void
49
49
50
+ override def checkIgnore (repo : File , file : String ): F [Boolean ] =
51
+ git_(" check-ignore" , file)(repo)
52
+ .as(true )
53
+ .recover { case _ : ProcessFailedException => false }
54
+
50
55
override def clone (repo : File , url : Uri ): F [Unit ] =
51
56
for {
52
57
rootDir <- workspaceAlg.rootDir
Original file line number Diff line number Diff line change @@ -34,6 +34,8 @@ trait GenGitAlg[F[_], Repo] {
34
34
35
35
def checkoutBranch (repo : Repo , branch : Branch ): F [Unit ]
36
36
37
+ def checkIgnore (repo : Repo , file : String ): F [Boolean ]
38
+
37
39
def clone (repo : Repo , url : Uri ): F [Unit ]
38
40
39
41
def cloneExists (repo : Repo ): F [Boolean ]
@@ -105,6 +107,9 @@ trait GenGitAlg[F[_], Repo] {
105
107
override def checkoutBranch (repo : A , branch : Branch ): F [Unit ] =
106
108
f(repo).flatMap(self.checkoutBranch(_, branch))
107
109
110
+ override def checkIgnore (repo : A , file : String ): F [Boolean ] =
111
+ f(repo).flatMap(self.checkIgnore(_, file))
112
+
108
113
override def clone (repo : A , url : Uri ): F [Unit ] =
109
114
f(repo).flatMap(self.clone(_, url))
110
115
Original file line number Diff line number Diff line change @@ -16,6 +16,32 @@ import org.scalasteward.core.util.Nel
16
16
class FileGitAlgTest extends CatsEffectSuite {
17
17
private val rootDir = mockRoot / " git-tests"
18
18
19
+ test(" add with .gitignore" ) {
20
+ val repo = rootDir / " branchgitignpreAuthors"
21
+ for {
22
+ _ <- ioAuxGitAlg.createRepo(repo)
23
+
24
+ gitIgnoreFile = repo / " .gitignore"
25
+ _ <- ioFileAlg.writeFile(gitIgnoreFile, " ignored.txt" )
26
+ _ <- ioAuxGitAlg.addFiles(repo, gitIgnoreFile)
27
+
28
+ ignoredFile = repo / " ignored.txt"
29
+ _ <- ioFileAlg.writeFile(ignoredFile, " irrelevant" )
30
+ ignoredFileCheck <- ioGitAlg.checkIgnore(repo, ignoredFile.pathAsString)
31
+
32
+ notIgnoredFile = repo / " not-ignored.txt"
33
+ _ <- ioFileAlg.writeFile(notIgnoredFile, " irrelevant" )
34
+ notIgnoredFileCheck <- ioGitAlg.checkIgnore(repo, notIgnoredFile.pathAsString)
35
+
36
+ } yield {
37
+ assert(ignoredFileCheck, " The file is in .gitignore, checkIgnore should return true." )
38
+ assert(
39
+ ! notIgnoredFileCheck,
40
+ " The file is not in .gitignore, checkIgnore should return false."
41
+ )
42
+ }
43
+ }
44
+
19
45
test(" branchAuthors" ) {
20
46
val repo = rootDir / " branchAuthors"
21
47
for {
You can’t perform that action at this time.
0 commit comments