Add RestoreStaged to Worktree that mimics the behaviour of git restore --staged <file>...#343
Add RestoreStaged to Worktree that mimics the behaviour of git restore --staged <file>...#343ben-tbotlabs wants to merge 8 commits intogo-git:masterfrom
Conversation
worktree.go
Outdated
| } | ||
|
|
||
| // unstages a set of files -- equivalent to "git restore --staged <file>..." | ||
| func (w *Worktree) RestoreStaged(files ...string) error { |
There was a problem hiding this comment.
I rather have the method Restore, with a RestoreOptions with Staged and Files as the fields.
There was a problem hiding this comment.
I can definitely make a change to the signature. I had files as a non-optional field because it is non-optional in the actual git command
git restore --staged
fatal: you must specify path(s) to restore
In the scenario where no files are provided should it just discard all staged changes?
There was a problem hiding this comment.
The options should have a validation, in case the options are invalid, must return an error
There was a problem hiding this comment.
I have converted to
type RestoreOptions struct {
// Marks to restore the content in the index
Staged bool
// Marks to restore the content of the working tree
Worktree bool
// List of file paths that will be restored
Files []string
}
func (w *Worktree) Restore(o *RestoreOptions) error
It will throw the same error string as git restore if no files are provided (ErrNoRestorePaths)
If only Worktree: true in the RestoreOptions then Restore will currently throw an error (ErrRestoreWorktreeeOnlyNotSupported) as I haven't had a chance to properly apply changes to the worktree without adjusting the Staged files
…(o *RestoreOptions) and add
…le options ( CheckoutOptions, CreateTagOptions, ...)
| "github.com/go-git/go-git/v5/plumbing/object" | ||
| "github.com/go-git/go-git/v5/storage/memory" | ||
|
|
||
| "github.com/go-git/go-billy/v5" |
There was a problem hiding this comment.
The test helper function
func setupForRestore(c *C, s *WorktreeSuite) (fs billy.Filesystem, w *Worktree, names []string)
Returns a billy.Filesystem, so I needed to get at the interface.
…he documentation standards
|
I am confused as to how my change is causing these test failures. Is there some internal state dependency I am not aware of between some of the tests? The latest commit seems to be passing so unless there is some transient build issues it must be something in my change. Any pointers would be appreciated to help track this down |
|
@mcuadros Would you be able to spare some time to help me track this down? |
…ee the source file was just using the name instead of the full path. Fix problems with files in subdirs not working
|
Any progress of this API? The capability is very useful. |
|
I was having problems with seemingly unrelated unit tests that I didn't figure out. I will bring this PR back up to head and try getting it resubmitted |
|
Closing this pull request because it has been replaced by #493 against updated master |
git: worktree, add RestoreStaged which works like the "git restore --staged ... Fixes #342