-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
ugit.demo.ps1
97 lines (59 loc) · 2.62 KB
/
ugit.demo.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# 1. ugitting started
# ugit updates git to make it work wonderfully in PowerShell.
# When you use ugit, git returns objects, not files.
git log -n 1
# Don't believe me? Just pipe to Get-Member
git log -n 1 |
Get-Member
# You can also pipe into git commands
Get-Item .\ugit.psd1 | git log
# git logs ain't all, ugit supports a bunch of git commands
git branch
# Let's use the object pipeline to filter out the current branch
git branch |
Where-Object -Not IsCurrentBranch
# Another cool thing ugit can do is -WhatIf. That will output the git command without running it.
git branch |
Where-Object -Not IsCurrentBranch |
git branch -d -WhatIf
# We can also git status
git status
# Let's make a little file, so that there are some changes
"hello world" | Set-Content .\hello.txt
# Now we can see our file in the status's .Untracked property (as fileinfo objects)
(git status).Untracked
# We can git diffs
git diff
# And get files with differences this way, too
(git diff).File
# Let's clean up our file
Remove-Item .\hello.txt
# 2. ugitting cooler
# ugit has started to extend the parameters of git
# some of these are simple, like --convenience parameters:
git log -After ([datetime]::Now.AddMonths(-1))
# Others are more interesting, like being able to get changes from the current branch:
git log -CurrentBranch
# Others make obscure git features easier to access. For example, let's search for any commits that changed ModuleVersion
git log -SearchPattern ModuleVersion
# Or, let's look for all commits related to issue #1
git log -IssueNumber 1
# Some improvements are subtle. For instance, we git clone will always add --progress, and will Write-Progress
git clone https://github.com/StartAutomating/ugit.git
# Let's clean that up.
Remove-Item .\ugit -Recurse -Force
# 3. ugit how it works
# ugit works with a few tricks of the PowerShell trade
# Aliases win over everything, so step one is to make git an alias to a function, Use-Git
Get-Command git
# When we override git, we can add extra parameters and parse it's output.
# We do this with ugit extensions.
Get-UGitExtension
# An extension can apply to Use-Git or Out-Git.
# Out-Git extensions turn git output into objects when the git command matches a pattern.
Get-UGitExtension -CommandName Out-Git
# Use-Git extensions add extra parameters to git when the command matches a pattern.
Get-UGitExtension -CommandName Use-Git
# Each extension returns a property bag, which can then be extended within ugit.types.ps1xml and formatted within a ugit.format.ps1xml.
# In this way, we can elegantly parse anything git throws at us, and leave the rest alone.
# ugit it?