Skip to content

Commit 28615c8

Browse files
authored
Update git module (#37)
* dropping files * unified code * adding blank tests file * updated new cmdlet decumentation and readme * first update-module tests * advanced removal * unattended installation requires force * changelog * Linux path update * more diagnostics * export nef function * OS specific PSModulesPath split * get-module and get-installedmodule difference * silent installation for better test log * supported psm1 only modules * external help updated
1 parent a16c11c commit 28615c8

19 files changed

+491
-54
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
PesterTestResults.xml
1+
PesterTestResults.xml
2+
en-US/InstallModuleFromGit-help.xml

ChangeLog.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
Date: TBA
44

5-
## new features in 1.0.1
5+
## new features in 1.1.0
6+
- new command Update-GitModule which installs module only if local version exists and if older than remote
67

7-
## bug fixes in 1.0.1
8+
## bug fixes in 1.1.0
89

910
# v.1.0.1
1011

Docs/Get-GitModule.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ Cmdlet requires \`git\` client tool to work.
2424
It will download (\`git clone\`) specified repository to temporary directory and analyze it.
2525
By default, it will delete this temporary copy, but if needed, it can be kept.
2626

27-
Cmdlet searches for module manifest ( .psd1) file only.
28-
Modules with only .psm1 files are not supported at the moment.
27+
Cmdlet searches for module manifest ( .psd1) file or if that is not found for module (.psm1) file itself.
2928

3029
## EXAMPLES
3130

Docs/Install-GitModule.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ Cmdlet will actually download specified repository to user's default install dir
2727

2828
It does not support functionality \`-Scope AllUsers\`, but it is possible to specify \`-DestinationPath\` argument which will provide the same result.
2929

30-
Cmdlet searches for module manifest ( .psd1) file only.
31-
Modules with only .psm1 files are not supported at the moment.
30+
Cmdlet searches for module manifest ( .psd1) file or if that is not found for module (.psm1) file itself.
3231

3332
Note that this will not import module, only install it (the same as built-in cmdlet \`Install-Module\`).
3433
You can rely on PowerShell's automatic import of modules into user session when needed.

Docs/InstallModuleFromGit-help.xml

Lines changed: 164 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<maml:description>
1313
<maml:para>This cmdlet will check for existence of PowerShell module in given repository and return its version. You can also specify desired git branch.</maml:para>
1414
<maml:para>Cmdlet requires `git` client tool to work. It will download (`git clone`) specified repository to temporary directory and analyze it. By default, it will delete this temporary copy, but if needed, it can be kept.</maml:para>
15-
<maml:para>Cmdlet searches for module manifest ( .psd1) file only. Modules with only .psm1 files are not supported at the moment.</maml:para>
15+
<maml:para>Cmdlet searches for module manifest ( .psd1) file or if that is not found for module (.psm1) file itself.</maml:para>
1616
</maml:description>
1717
<command:syntax>
1818
<command:syntaxItem>
@@ -162,7 +162,7 @@ Git : https://github.com/iricigor/FIFA2018</dev:code>
162162
<maml:para>You can also specify desired git branch.</maml:para>
163163
<maml:para>Cmdlet internally uses `Get-GitModule` cmdlet, so it requires `git` client tool to work. Cmdlet will actually download specified repository to user's default install directory for PowerShell modules.</maml:para>
164164
<maml:para>It does not support functionality `-Scope AllUsers`, but it is possible to specify `-DestinationPath` argument which will provide the same result.</maml:para>
165-
<maml:para>Cmdlet searches for module manifest ( .psd1) file only. Modules with only .psm1 files are not supported at the moment.</maml:para>
165+
<maml:para>Cmdlet searches for module manifest ( .psd1) file or if that is not found for module (.psm1) file itself.</maml:para>
166166
<maml:para>Note that this will not import module, only install it (the same as built-in cmdlet `Install-Module`). You can rely on PowerShell's automatic import of modules into user session when needed.</maml:para>
167167
</maml:description>
168168
<command:syntax>
@@ -305,4 +305,166 @@ Git : https://github.com/iricigor/FIFA2018</dev:code>
305305
</command:examples>
306306
<command:relatedLinks />
307307
</command:command>
308+
<command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10" xmlns:MSHelp="http://msdn.microsoft.com/mshelp">
309+
<command:details>
310+
<command:name>Update-GitModule</command:name>
311+
<command:verb>Update</command:verb>
312+
<command:noun>GitModule</command:noun>
313+
<maml:description>
314+
<maml:para>This cmdlet updates previously installed PowerShell module specified by its git repository URL if repository contains newer version than installed one.</maml:para>
315+
</maml:description>
316+
</command:details>
317+
<maml:description>
318+
<maml:para>This cmdlet updates previously installed PowerShell module specified by its git repository URL if repository contains newer version than installed one.</maml:para>
319+
<maml:para>You can also specify desired git branch.</maml:para>
320+
<maml:para>Cmdlet internally uses `Get-GitModule` cmdlet, so it requires `git` client tool to work. Cmdlet will actually download specified repository to user's default install directory for PowerShell modules.</maml:para>
321+
<maml:para>Cmdlet searches for module manifest ( .psd1) file or if that is not found for module (.psm1) file itself.</maml:para>
322+
<maml:para>If you do not have the same module already installed, commandlet will throw an error.</maml:para>
323+
<maml:para>Note that this will not import module, only install it (the same as built-in cmdlet `Update-Module`). You can rely on PowerShell's automatic import of modules into user session when needed.</maml:para>
324+
</maml:description>
325+
<command:syntax>
326+
<command:syntaxItem>
327+
<maml:name>Update-GitModule</maml:name>
328+
<command:parameter required="true" variableLength="true" globbing="false" pipelineInput="True (ByPropertyName)" position="0" aliases="none">
329+
<maml:name>ProjectUri</maml:name>
330+
<maml:Description>
331+
<maml:para>Mandatory parameter specifying URL or the repository. Multiple values are supported. Parameter is passed to `git` client, so whatever works there is good value. For example, in GitHub URLs you can specify parameter both with or without `.git` at the end of URL.</maml:para>
332+
<maml:para>You can pass this parameter also via pipeline, for example via `Find-Module` built-in cmdlet.</maml:para>
333+
</maml:Description>
334+
<command:parameterValue required="true" variableLength="false">String[]</command:parameterValue>
335+
<dev:type>
336+
<maml:name>String[]</maml:name>
337+
<maml:uri />
338+
</dev:type>
339+
<dev:defaultValue>None</dev:defaultValue>
340+
</command:parameter>
341+
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
342+
<maml:name>Branch</maml:name>
343+
<maml:Description>
344+
<maml:para>Optional parameter that specifies which branch should be cloned. If omitted, `master` branch will be used.</maml:para>
345+
</maml:Description>
346+
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
347+
<dev:type>
348+
<maml:name>String</maml:name>
349+
<maml:uri />
350+
</dev:type>
351+
<dev:defaultValue>None</dev:defaultValue>
352+
</command:parameter>
353+
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
354+
<maml:name>DestinationPath</maml:name>
355+
<maml:Description>
356+
<maml:para>If you have a specific setup, you can override default install location with this parameter. As cmdlet always installs to user specific location, this can be useful to perform system wide installation (requires also elevated prompt).</maml:para>
357+
</maml:Description>
358+
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
359+
<dev:type>
360+
<maml:name>String</maml:name>
361+
<maml:uri />
362+
</dev:type>
363+
<dev:defaultValue>None</dev:defaultValue>
364+
</command:parameter>
365+
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
366+
<maml:name>Force</maml:name>
367+
<maml:Description>
368+
<maml:para>If DestinationPath location is not empty, commandlet will not install newer version there. This behavior can be overridden with -Force switch.</maml:para>
369+
</maml:Description>
370+
<dev:type>
371+
<maml:name>SwitchParameter</maml:name>
372+
<maml:uri />
373+
</dev:type>
374+
<dev:defaultValue>False</dev:defaultValue>
375+
</command:parameter>
376+
</command:syntaxItem>
377+
</command:syntax>
378+
<command:parameters>
379+
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
380+
<maml:name>Branch</maml:name>
381+
<maml:Description>
382+
<maml:para>Optional parameter that specifies which branch should be cloned. If omitted, `master` branch will be used.</maml:para>
383+
</maml:Description>
384+
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
385+
<dev:type>
386+
<maml:name>String</maml:name>
387+
<maml:uri />
388+
</dev:type>
389+
<dev:defaultValue>None</dev:defaultValue>
390+
</command:parameter>
391+
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
392+
<maml:name>DestinationPath</maml:name>
393+
<maml:Description>
394+
<maml:para>If you have a specific setup, you can override default install location with this parameter. As cmdlet always installs to user specific location, this can be useful to perform system wide installation (requires also elevated prompt).</maml:para>
395+
</maml:Description>
396+
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
397+
<dev:type>
398+
<maml:name>String</maml:name>
399+
<maml:uri />
400+
</dev:type>
401+
<dev:defaultValue>None</dev:defaultValue>
402+
</command:parameter>
403+
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
404+
<maml:name>Force</maml:name>
405+
<maml:Description>
406+
<maml:para>If DestinationPath location is not empty, commandlet will not install newer version there. This behavior can be overridden with -Force switch.</maml:para>
407+
</maml:Description>
408+
<command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue>
409+
<dev:type>
410+
<maml:name>SwitchParameter</maml:name>
411+
<maml:uri />
412+
</dev:type>
413+
<dev:defaultValue>False</dev:defaultValue>
414+
</command:parameter>
415+
<command:parameter required="true" variableLength="true" globbing="false" pipelineInput="True (ByPropertyName)" position="0" aliases="none">
416+
<maml:name>ProjectUri</maml:name>
417+
<maml:Description>
418+
<maml:para>Mandatory parameter specifying URL or the repository. Multiple values are supported. Parameter is passed to `git` client, so whatever works there is good value. For example, in GitHub URLs you can specify parameter both with or without `.git` at the end of URL.</maml:para>
419+
<maml:para>You can pass this parameter also via pipeline, for example via `Find-Module` built-in cmdlet.</maml:para>
420+
</maml:Description>
421+
<command:parameterValue required="true" variableLength="false">String[]</command:parameterValue>
422+
<dev:type>
423+
<maml:name>String[]</maml:name>
424+
<maml:uri />
425+
</dev:type>
426+
<dev:defaultValue>None</dev:defaultValue>
427+
</command:parameter>
428+
</command:parameters>
429+
<command:inputTypes>
430+
<command:inputType>
431+
<dev:type>
432+
<maml:name>System.String[]</maml:name>
433+
</dev:type>
434+
<maml:description>
435+
<maml:para></maml:para>
436+
</maml:description>
437+
</command:inputType>
438+
</command:inputTypes>
439+
<command:returnValues>
440+
<command:returnValue>
441+
<dev:type>
442+
<maml:name>System.Object</maml:name>
443+
</dev:type>
444+
<maml:description>
445+
<maml:para></maml:para>
446+
</maml:description>
447+
</command:returnValue>
448+
</command:returnValues>
449+
<maml:alertSet>
450+
<maml:alert>
451+
<maml:para></maml:para>
452+
</maml:alert>
453+
</maml:alertSet>
454+
<command:examples>
455+
<command:example>
456+
<maml:title>-------------------------- Example 1 --------------------------</maml:title>
457+
<dev:code>PS C:\&gt; Update-GitModule https://github.com/microsoft/SpeculationControl</dev:code>
458+
<dev:remarks>
459+
<maml:para>Updates the most downloadable PowerShell module directly from GitHub. If you do not have it installed, it will throw an error.</maml:para>
460+
</dev:remarks>
461+
</command:example>
462+
</command:examples>
463+
<command:relatedLinks>
464+
<maml:navigationLink>
465+
<maml:linkText>https://github.com/iricigor/InstallModuleFromGit/blob/master/Docs/Update-GitModule.md</maml:linkText>
466+
<maml:uri>https://github.com/iricigor/InstallModuleFromGit/blob/master/Docs/Update-GitModule.md</maml:uri>
467+
</maml:navigationLink>
468+
</command:relatedLinks>
469+
</command:command>
308470
</helpItems>

Docs/Update-GitModule.md

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
---
2+
external help file: InstallModuleFromGit-help.xml
3+
Module Name: InstallModuleFromGit
4+
online version: https://github.com/iricigor/InstallModuleFromGit/blob/master/Docs/Update-GitModule.md
5+
schema: 2.0.0
6+
---
7+
8+
# Update-GitModule
9+
10+
## SYNOPSIS
11+
This cmdlet updates previously installed PowerShell module specified by its git repository URL if repository contains newer version than installed one.
12+
13+
## SYNTAX
14+
15+
```
16+
Update-GitModule [-ProjectUri] <String[]> [-Branch <String>] [-DestinationPath <String>] [-Force]
17+
[<CommonParameters>]
18+
```
19+
20+
## DESCRIPTION
21+
22+
This cmdlet updates previously installed PowerShell module specified by its git repository URL if repository contains newer version than installed one.
23+
24+
You can also specify desired git branch.
25+
26+
Cmdlet internally uses \`Get-GitModule\` cmdlet, so it requires \`git\` client tool to work.
27+
Cmdlet will actually download specified repository to user's default install directory for PowerShell modules.
28+
29+
Cmdlet searches for module manifest ( .psd1) file or if that is not found for module (.psm1) file itself.
30+
31+
If you do not have the same module already installed, commandlet will throw an error.
32+
33+
Note that this will not import module, only install it (the same as built-in cmdlet \`Update-Module\`).
34+
You can rely on PowerShell's automatic import of modules into user session when needed.
35+
36+
## EXAMPLES
37+
38+
### Example 1
39+
```powershell
40+
PS C:\> Update-GitModule https://github.com/microsoft/SpeculationControl
41+
```
42+
43+
Updates the most downloadable PowerShell module directly from GitHub. If you do not have it installed, it will throw an error.
44+
45+
## PARAMETERS
46+
47+
### -Branch
48+
Optional parameter that specifies which branch should be cloned.
49+
If omitted, \`master\` branch will be used.
50+
51+
```yaml
52+
Type: String
53+
Parameter Sets: (All)
54+
Aliases:
55+
56+
Required: False
57+
Position: Named
58+
Default value: None
59+
Accept pipeline input: False
60+
Accept wildcard characters: False
61+
```
62+
63+
### -DestinationPath
64+
If you have a specific setup, you can override default install location with this parameter.
65+
As cmdlet always installs to user specific location, this can be useful to perform system wide installation (requires also elevated prompt).
66+
67+
```yaml
68+
Type: String
69+
Parameter Sets: (All)
70+
Aliases:
71+
72+
Required: False
73+
Position: Named
74+
Default value: None
75+
Accept pipeline input: False
76+
Accept wildcard characters: False
77+
```
78+
79+
### -Force
80+
If DestinationPath location is not empty, commandlet will not install newer version there.
81+
This behavior can be overridden with -Force switch.
82+
83+
```yaml
84+
Type: SwitchParameter
85+
Parameter Sets: (All)
86+
Aliases:
87+
88+
Required: False
89+
Position: Named
90+
Default value: None
91+
Accept pipeline input: False
92+
Accept wildcard characters: False
93+
```
94+
95+
### -ProjectUri
96+
Mandatory parameter specifying URL or the repository.
97+
Multiple values are supported.
98+
Parameter is passed to \`git\` client, so whatever works there is good value.
99+
For example, in GitHub URLs you can specify parameter both with or without \`.git\` at the end of URL.
100+
101+
You can pass this parameter also via pipeline, for example via \`Find-Module\` built-in cmdlet.
102+
103+
```yaml
104+
Type: String[]
105+
Parameter Sets: (All)
106+
Aliases:
107+
108+
Required: True
109+
Position: 0
110+
Default value: None
111+
Accept pipeline input: True (ByPropertyName)
112+
Accept wildcard characters: False
113+
```
114+
115+
### CommonParameters
116+
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
117+
118+
## INPUTS
119+
120+
### System.String[]
121+
122+
## OUTPUTS
123+
124+
### System.Object
125+
## NOTES
126+
127+
## RELATED LINKS
128+
129+
[https://github.com/iricigor/InstallModuleFromGit/blob/master/Docs/Update-GitModule.md](https://github.com/iricigor/InstallModuleFromGit/blob/master/Docs/Update-GitModule.md)
130+

InstallModuleFromGit.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Description = 'Installs module from Git repository (i.e. GitHUb or Azure DevOps)
6969
# NestedModules = @()
7070

7171
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
72-
FunctionsToExport = @('Get-GitModule','Install-GitModule')
72+
FunctionsToExport = @('Get-GitModule','Install-GitModule','Update-GitModule')
7373

7474
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
7575
CmdletsToExport = @()

Private/Get-InstallPath.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ function Get-InstallPath {
22

33
# returns OS specific path for module installation, it support only -Scope CurrentUser
44
if ($IsLinux -or $IsOSX) {
5-
"$HOME/.local/share/powershell/Modules"
5+
#"$HOME/.local/share/powershell/Modules"
6+
# https://github.com/PowerShell/PowerShellGet/blob/d4dfebbbec4dfbe73392719a8a331541ed75d508/src/PowerShellGet/private/modulefile/PartOne.ps1#L71
7+
Join-Path (Split-Path -Path ([System.Management.Automation.Platform]::SelectProductNameForDirectory('USER_MODULES')) -Parent) 'Modules'
68
} else {
79
# https://github.com/PowerShell/PowerShellGet/blob/8004c304a2fa8ad32b92c6c2ba7efe116df3c862/src/PowerShellGet/private/modulefile/PartOne.ps1#L46
810
try {

0 commit comments

Comments
 (0)