-
Notifications
You must be signed in to change notification settings - Fork 798
Add RestoreStaged to Worktree that mimics the behaviour of git restore --staged <file>... #343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
worktree.go
Outdated
@@ -262,6 +262,16 @@ func (w *Worktree) setHEADToBranch(branch plumbing.ReferenceName, commit plumbin | |||
return w.r.Storer.SetReference(head) | |||
} | |||
|
|||
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I rather have the method Restore
, with a RestoreOptions
with Staged
and Files
as the fields.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The options should have a validation, in case the options are invalid, must return an error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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, ...)
@@ -22,6 +23,7 @@ import ( | |||
"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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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