PoshCode / PSGit

A PowerShell implementation of Git, mapping git commands to Verb-Noun and objects.
105 stars 15 forks source link

Add-Change #2

Open Jaykul opened 9 years ago

Jaykul commented 9 years ago

Before we can do anything else, we have to add changes to the current index. How should this behave? Should it add * by default?

jrich523 commented 9 years ago

Just trying to think of how this would be used... here are some methods it could be used

gci *.ps1 | add-gitchange # binds to inputobject [FileSystemInfo] has full name, doesnt need root get-gitchange | add-gitchange # property binding path, needs root $stringPaths | add-gitchange # string path binding, may or may not need root, wildcard support?

add-gitchange $filePath #position 0 Path add-gitchange -pathspec $spec add-gitchange -all

Jaykul commented 9 years ago

Forgive me if I speak out of turn, I'm deliberately not looking at the spec to remember what it says, and just trying to think what I expect. I think that for most of these commands you're going to want to take a root parameter so that (unlike git.exe) you don't have to switch the working directory before running the command.

Generally, just like the way Get-Change and Get-Info do it:

        [Parameter()]
        [ValidateNotNullOrEmpty()]
        [String]$Root = $Pwd

and then at the top of your logic ...

        $Path = Get-RootFolder $Root
        if(!$Path) {
            Write-Warning "The path is not in a git repository!"
            return
        }

In the case of file paths being sent to Add-GitChange, presumably you can deduce $Root from the path, if it's not explicitly set.

Should Get-GitChange add a PSPath (alias property to Path) to the items, so that we can use that to bind paths?
Jaykul commented 9 years ago

May I suggest adding an equivalent feature to --dry-run: And it should support ShouldContinue # -Whatif -Confirm

Additional examples:

add-gitchange *.ps1 -all # pathspec + all is confusing -- should we support that?
add-gitchange tests\* -update # pathspec + update only
add-gitchange .\output\readme.md -force
add-gitchange -whatif

I would kind-of love it if -confirm could be like --patch ... git add --patch is the bomb (incidentally, it can't be, because --patch needs more options than ShouldContinue has :wink:)

jrich523 commented 9 years ago

i actually took that code already... i guess mostly what i was concerned about was passing 3 different types by pipe... filesysteminfo(binds to inputobject), strings (full path, partial path), change objects (binds to path by propertyname)..

jrich523 commented 9 years ago

path spec wouldnt be positional.. so.. none of that would work..

Jaykul commented 9 years ago

What :interrobang: :suspect:

jrich523 commented 9 years ago

so i think the -all is to just say add all changes, which, im not sure thats needed since you could just do

get-gitchange | add-gitchange

but, that was CMU's so i think we'd need to hear from him.

as far as the -whatif, i assume you are doing that as shorthand, and wouldnt expect add-gitchange -whatif to do anything on its own? it would need some form of additions... i assume thats the case, but thought i'd double check.

also, im not sure that -update is all that useful (if i understand it correctly, it stages only updated files, not new files) that could again easily be done with get/add

I really like how he added details about what they are, but as i think about it, that could be added to the table as the param description definition, two birds one stone :)

I still havent figured a good way to do this, as horrible as it is, i think a huge table might be good...