Skip to content

Instantly share code, notes, and snippets.

@Gimly
Last active September 8, 2016 12:37
Show Gist options
  • Save Gimly/b865b0ed09f0f9fe13d12f6b0137ecfb to your computer and use it in GitHub Desktop.
Save Gimly/b865b0ed09f0f9fe13d12f6b0137ecfb to your computer and use it in GitHub Desktop.
Exports the list of files modified between two commit ids (or tag ids) to a zip archive.
param(
# Git tag or commit has from which we want the patch to start
[String] $FromTag,
# Path of the patch file
[String] $PatchFilePath,
# Git tag or commit hash where to we want the patch to update to (default HEAD, current checkout)
[String] $ToTag = "HEAD"
)
function New-ZipFromFiles (
# The name and path of the resulting ZIP file
[Parameter(Mandatory = $true)]
[String] $ZipFilename,
# The source directory to compress into a zip
[Parameter(Mandatory = $true)]
[ValidateScript({Test-Path $_ -PathType Container})]
[String] $SourceDir)
{
Add-Type -Assembly System.IO.Compression.FileSystem
$absoluteSourcePath = Resolve-Path $SourceDir
$resultPath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($ZipFilename)
$compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal
[System.IO.Compression.ZipFile]::CreateFromDirectory(
$absoluteSourcePath,
$resultPath,
$compressionLevel,
$false)
}
$modifiedFiles = git diff "$FromTag..$ToTag" --no-commit-id --name-only --diff-filter=ACMRT
foreach ($itemToCopy in $modifiedFiles)
{
$targetFolder = Split-Path $itemToCopy
$targetFileName = Split-Path $itemToCopy -Leaf
$targetFolder = Join-Path ./Temp $targetFolder
$targetPathAndFile = Join-Path $targetFolder $targetFileName
# If destination folder doesn't exist
if (!(Test-Path $targetFolder -PathType Container)) {
# Create destination folder
New-Item -Path $targetFolder -ItemType Directory -Force
}
Copy-Item -Path $itemToCopy -Destination $targetPathAndFile
}
$PatchFilePath
New-ZipFromFiles $PatchFilePath "./Temp"
Remove-Item -Recurse -Force ./Temp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment