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

[REQUEST] Stage files/hunks from diff file

Open kdiogenes opened this issue 8 years ago • 2 comments

https://github.com/divmain/GitSavvy is a sublime plugin that has a feature that I would like to also see in this plugin.

While in the diff panel, you can hit ctrl+enter to stage files/hunks. It's amazing!

If you can give a feedback about the direction of how this can be implemented (Until now, I only scratched some atom plugins code), I can provide an implementation.

Best regards!

kdiogenes avatar Jan 10 '17 14:01 kdiogenes

#246 is a request for staging hunks by selecting portions of a file. I think doing it from the diff view is a better idea though.

As far as implementation, staging hunks programmatically is not obvious. You can check out the implementation of staging hunks in this package right now at in https://github.com/akonwi/git-plus/blob/master/lib/views/select-stage-hunks-view.coffee. At line 68 objects for each hunk are generated from a diff string and then at line 49 there's some work done with the object in order to create the commit.

I have to admit I didn't write any of that code and I haven't taken time to understand it fully.

akonwi avatar Jan 10 '17 17:01 akonwi

I've spent some time trying to figure out what it would take to make this feature a reality and I don't think this will be trivial. Currently, diffs are displayed simply as a text file. So in order to respond to some command to stage a hunk/line/whatever, it's necessary to know the details of the hunk. To get that info, the first thought was to look for the closest diff header above the cursor or selected area. That sucks. Alternatively, each hunk displayed in the diff can be wrapped in a marker or decorator from Atom's API but I don't like that either.

I think the way diffs are displayed needs to be rewritten into a component of some sort instead of as just a file in order to reasonably implement this feature. Rewriting that stuff won't be easy. I'm not going to tackle it right now because I think there are other priorities but I'd love to see it happen.

akonwi avatar Jan 18 '17 21:01 akonwi