Skip to content

Update git module #37

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

Merged
merged 16 commits into from
Jun 10, 2019
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
PesterTestResults.xml
PesterTestResults.xml
en-US/InstallModuleFromGit-help.xml
5 changes: 3 additions & 2 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

Date: TBA

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

## bug fixes in 1.0.1
## bug fixes in 1.1.0

# v.1.0.1

Expand Down
3 changes: 1 addition & 2 deletions Docs/Get-GitModule.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ 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.

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

## EXAMPLES

Expand Down
3 changes: 1 addition & 2 deletions Docs/Install-GitModule.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ Cmdlet will actually download specified repository to user's default install dir

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

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

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.
Expand Down
166 changes: 164 additions & 2 deletions Docs/InstallModuleFromGit-help.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<maml:description>
<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>
<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>
<maml:para>Cmdlet searches for module manifest ( .psd1) file only. Modules with only .psm1 files are not supported at the moment.</maml:para>
<maml:para>Cmdlet searches for module manifest ( .psd1) file or if that is not found for module (.psm1) file itself.</maml:para>
</maml:description>
<command:syntax>
<command:syntaxItem>
Expand Down Expand Up @@ -162,7 +162,7 @@ Git : https://github.com/iricigor/FIFA2018</dev:code>
<maml:para>You can also specify desired git branch.</maml:para>
<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>
<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>
<maml:para>Cmdlet searches for module manifest ( .psd1) file only. Modules with only .psm1 files are not supported at the moment.</maml:para>
<maml:para>Cmdlet searches for module manifest ( .psd1) file or if that is not found for module (.psm1) file itself.</maml:para>
<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>
</maml:description>
<command:syntax>
Expand Down Expand Up @@ -305,4 +305,166 @@ Git : https://github.com/iricigor/FIFA2018</dev:code>
</command:examples>
<command:relatedLinks />
</command:command>
<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">
<command:details>
<command:name>Update-GitModule</command:name>
<command:verb>Update</command:verb>
<command:noun>GitModule</command:noun>
<maml:description>
<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>
</maml:description>
</command:details>
<maml:description>
<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>
<maml:para>You can also specify desired git branch.</maml:para>
<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>
<maml:para>Cmdlet searches for module manifest ( .psd1) file or if that is not found for module (.psm1) file itself.</maml:para>
<maml:para>If you do not have the same module already installed, commandlet will throw an error.</maml:para>
<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>
</maml:description>
<command:syntax>
<command:syntaxItem>
<maml:name>Update-GitModule</maml:name>
<command:parameter required="true" variableLength="true" globbing="false" pipelineInput="True (ByPropertyName)" position="0" aliases="none">
<maml:name>ProjectUri</maml:name>
<maml:Description>
<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>
<maml:para>You can pass this parameter also via pipeline, for example via `Find-Module` built-in cmdlet.</maml:para>
</maml:Description>
<command:parameterValue required="true" variableLength="false">String[]</command:parameterValue>
<dev:type>
<maml:name>String[]</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>Branch</maml:name>
<maml:Description>
<maml:para>Optional parameter that specifies which branch should be cloned. If omitted, `master` branch will be used.</maml:para>
</maml:Description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
<dev:type>
<maml:name>String</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>DestinationPath</maml:name>
<maml:Description>
<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>
</maml:Description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
<dev:type>
<maml:name>String</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>Force</maml:name>
<maml:Description>
<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>
</maml:Description>
<dev:type>
<maml:name>SwitchParameter</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>False</dev:defaultValue>
</command:parameter>
</command:syntaxItem>
</command:syntax>
<command:parameters>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>Branch</maml:name>
<maml:Description>
<maml:para>Optional parameter that specifies which branch should be cloned. If omitted, `master` branch will be used.</maml:para>
</maml:Description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
<dev:type>
<maml:name>String</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>DestinationPath</maml:name>
<maml:Description>
<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>
</maml:Description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
<dev:type>
<maml:name>String</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>Force</maml:name>
<maml:Description>
<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>
</maml:Description>
<command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue>
<dev:type>
<maml:name>SwitchParameter</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>False</dev:defaultValue>
</command:parameter>
<command:parameter required="true" variableLength="true" globbing="false" pipelineInput="True (ByPropertyName)" position="0" aliases="none">
<maml:name>ProjectUri</maml:name>
<maml:Description>
<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>
<maml:para>You can pass this parameter also via pipeline, for example via `Find-Module` built-in cmdlet.</maml:para>
</maml:Description>
<command:parameterValue required="true" variableLength="false">String[]</command:parameterValue>
<dev:type>
<maml:name>String[]</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
</command:parameters>
<command:inputTypes>
<command:inputType>
<dev:type>
<maml:name>System.String[]</maml:name>
</dev:type>
<maml:description>
<maml:para></maml:para>
</maml:description>
</command:inputType>
</command:inputTypes>
<command:returnValues>
<command:returnValue>
<dev:type>
<maml:name>System.Object</maml:name>
</dev:type>
<maml:description>
<maml:para></maml:para>
</maml:description>
</command:returnValue>
</command:returnValues>
<maml:alertSet>
<maml:alert>
<maml:para></maml:para>
</maml:alert>
</maml:alertSet>
<command:examples>
<command:example>
<maml:title>-------------------------- Example 1 --------------------------</maml:title>
<dev:code>PS C:\&gt; Update-GitModule https://github.com/microsoft/SpeculationControl</dev:code>
<dev:remarks>
<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>
</dev:remarks>
</command:example>
</command:examples>
<command:relatedLinks>
<maml:navigationLink>
<maml:linkText>https://github.com/iricigor/InstallModuleFromGit/blob/master/Docs/Update-GitModule.md</maml:linkText>
<maml:uri>https://github.com/iricigor/InstallModuleFromGit/blob/master/Docs/Update-GitModule.md</maml:uri>
</maml:navigationLink>
</command:relatedLinks>
</command:command>
</helpItems>
130 changes: 130 additions & 0 deletions Docs/Update-GitModule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
---
external help file: InstallModuleFromGit-help.xml
Module Name: InstallModuleFromGit
online version: https://github.com/iricigor/InstallModuleFromGit/blob/master/Docs/Update-GitModule.md
schema: 2.0.0
---

# Update-GitModule

## SYNOPSIS
This cmdlet updates previously installed PowerShell module specified by its git repository URL if repository contains newer version than installed one.

## SYNTAX

```
Update-GitModule [-ProjectUri] <String[]> [-Branch <String>] [-DestinationPath <String>] [-Force]
[<CommonParameters>]
```

## DESCRIPTION

This cmdlet updates previously installed PowerShell module specified by its git repository URL if repository contains newer version than installed one.

You can also specify desired git branch.

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.

Cmdlet searches for module manifest ( .psd1) file or if that is not found for module (.psm1) file itself.

If you do not have the same module already installed, commandlet will throw an error.

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.

## EXAMPLES

### Example 1
```powershell
PS C:\> Update-GitModule https://github.com/microsoft/SpeculationControl
```

Updates the most downloadable PowerShell module directly from GitHub. If you do not have it installed, it will throw an error.

## PARAMETERS

### -Branch
Optional parameter that specifies which branch should be cloned.
If omitted, \`master\` branch will be used.

```yaml
Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -DestinationPath
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).

```yaml
Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Force
If DestinationPath location is not empty, commandlet will not install newer version there.
This behavior can be overridden with -Force switch.

```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -ProjectUri
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.

You can pass this parameter also via pipeline, for example via \`Find-Module\` built-in cmdlet.

```yaml
Type: String[]
Parameter Sets: (All)
Aliases:

Required: True
Position: 0
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```

### CommonParameters
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).

## INPUTS

### System.String[]

## OUTPUTS

### System.Object
## NOTES

## RELATED LINKS

[https://github.com/iricigor/InstallModuleFromGit/blob/master/Docs/Update-GitModule.md](https://github.com/iricigor/InstallModuleFromGit/blob/master/Docs/Update-GitModule.md)

2 changes: 1 addition & 1 deletion InstallModuleFromGit.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Description = 'Installs module from Git repository (i.e. GitHUb or Azure DevOps)
# NestedModules = @()

# 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.
FunctionsToExport = @('Get-GitModule','Install-GitModule')
FunctionsToExport = @('Get-GitModule','Install-GitModule','Update-GitModule')

# 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.
CmdletsToExport = @()
Expand Down
4 changes: 3 additions & 1 deletion Private/Get-InstallPath.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ function Get-InstallPath {

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