git-down icon indicating copy to clipboard operation
git-down copied to clipboard

Create Git.stageLines extension

Open codymikol opened this issue 3 years ago • 2 comments

This should accept a list of line numbers to stage and add only those lines into staging.

codymikol avatar Jun 19 '22 14:06 codymikol

Essentially my thoughts on this are to take the current diff in the working tree

@@ -1, 7 _1, 7 @@
 a
-b
+B
 c
+d

Say we want to stage lines 2 & 3, we will create a diff with only those lines and apply that

codymikol avatar Nov 23 '22 22:11 codymikol

F to my entire sunday and this code that didn't work


//    val toAddFilePatterns = fileDeltaNode.fileDelta.getPath()
//    val repo = GitDownState.repo.value
//
//    var dc: DirCache? = null
//
//    try {
//
//        val objectInserter = repo.newObjectInserter()
//        val treeWalk = NameConflictTreeWalk(repo)
//
//        treeWalk.operationType = OperationType.CHECKIN_OP
//
//        dc = repo.lockDirCache()
//
//        val builder = dc.builder()
//
//        treeWalk.addTree(DirCacheBuildIterator(builder))
//
//        val workingTreeIterator = FileTreeIterator(repo)
//
//        workingTreeIterator.setDirCacheIterator(treeWalk, 0)
//        treeWalk.addTree(workingTreeIterator)
//
//        val pathFilter = PathFilterGroup.createFromStrings(toAddFilePatterns)
//
//        treeWalk.filter = pathFilter
//
//        while(treeWalk.next()) {
//            val cache = treeWalk.getTree(0, DirCacheIterator::class.java)
//            val file = treeWalk.getTree(1, WorkingTreeIterator::class.java)
//            val path = treeWalk.rawPath
//            val entry = DirCacheEntry(path)
//            val fileMode = file.getIndexFileMode(cache)
//
//            file
//
////            val len = file.entryContentLength
//
//            //todo(mikol): FIXME
//            val patchedFile = "b"
//            val byteArray = patchedFile.toByteArray()
//            val inputStream = ByteArrayInputStream(byteArray)
//
////            val inputStream = file.openEntryStream()
//
//            entry.fileMode = fileMode
//            entry.length = getInputStreamLength(inputStream).toInt()
//
////            entry.length = file.entryLength.toInt()
//            entry.setLastModified(file.entryLastModifiedInstant)
//
//            try {
//                val id = objectInserter.insert(OBJ_BLOB, len, inputStream)
//                entry.setObjectId(id)
//            } catch (e: Exception) {
//                //todo(mikol): do something less useless
//                logger.error("AHHHHHHHHHHHHHHHHHHHHHH")
//            }
//            builder.add(entry)
//
//        }
//
//        objectInserter.flush()
//        builder.commit()
//
//    } catch (e: IOException) {
//        println("SAD")
//    } finally {
//        dc?.unlock()
//    }

codymikol avatar Sep 24 '23 21:09 codymikol