Skip to content

Commit

Permalink
Discarding hunks now always uses UTF-8
Browse files Browse the repository at this point in the history
Fixes #170
  • Loading branch information
JetpackDuba committed Nov 11, 2023
1 parent 0ea427c commit 81c3704
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import kotlinx.coroutines.withContext
import org.eclipse.jgit.api.Git
import javax.inject.Inject

class ResetEntryUseCase @Inject constructor() {
class DiscardEntryUseCase @Inject constructor() {
suspend operator fun invoke(git: Git, statusEntry: StatusEntry, staged: Boolean): Unit =
withContext(Dispatchers.IO) {
if (staged || statusEntry.statusType == StatusType.CONFLICTING) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.jetpackduba.gitnuro.git.workspace

import com.jetpackduba.gitnuro.extensions.filePath
import com.jetpackduba.gitnuro.extensions.lineDelimiter
import com.jetpackduba.gitnuro.git.diff.Hunk
import com.jetpackduba.gitnuro.git.diff.Line
import com.jetpackduba.gitnuro.git.diff.LineType
Expand All @@ -10,7 +9,6 @@ import kotlinx.coroutines.withContext
import org.eclipse.jgit.api.Git
import org.eclipse.jgit.diff.DiffEntry
import java.io.File
import java.io.FileWriter
import javax.inject.Inject

class DiscardUnstagedHunkLineUseCase @Inject constructor(
Expand All @@ -22,7 +20,7 @@ class DiscardUnstagedHunkLineUseCase @Inject constructor(

try {
val file = File(repository.workTree, diffEntry.filePath)
val content = file.readText()
val content = file.readText(Charsets.UTF_8)
val textLines = getLinesFromTextUseCase(content).toMutableList()

if (line.lineType == LineType.ADDED) {
Expand All @@ -47,13 +45,9 @@ class DiscardUnstagedHunkLineUseCase @Inject constructor(
}
}

println(content)
val resultText = textLines.joinToString("")
file.writeText(resultText, Charsets.UTF_8)


FileWriter(file).use { fw ->
fw.write(resultText)
}
} catch (ex: Exception) {
throw Exception(
"Discard hunk line failed. Check if the file still exists and has the write permissions set",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class StatusViewModel @Inject constructor(
private val tabState: TabState,
private val stageEntryUseCase: StageEntryUseCase,
private val unstageEntryUseCase: UnstageEntryUseCase,
private val resetEntryUseCase: ResetEntryUseCase,
private val resetEntryUseCase: DiscardEntryUseCase,
private val stageAllUseCase: StageAllUseCase,
private val unstageAllUseCase: UnstageAllUseCase,
private val checkHasPreviousCommitsUseCase: CheckHasPreviousCommitsUseCase,
Expand Down

0 comments on commit 81c3704

Please sign in to comment.