git-down
git-down copied to clipboard
Create Git.stageLines extension
This should accept a list of line numbers to stage and add only those lines into staging.
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
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()
// }