Created
April 12, 2012 22:19
-
-
Save laurentkempe/2371417 to your computer and use it in GitHub Desktop.
Sending your Git branch changes as an email attachment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-GitBranch { | |
$symbolicref = git symbolic-ref HEAD | |
$branch = $symbolicref.substring($symbolicref.LastIndexOf("/") +1) | |
return $branch | |
} | |
function Zip-GitBranch([string]$zipFilename) { | |
$branch = Get-GitBranch | |
if (!$zipFilename) { | |
$zipFilename = [string]::Format(".\{0}.zip", $branch) | |
} | |
$files = git diff --name-only HEAD..master | |
foreach($file in $files) { | |
& 'C:\Program Files\7-Zip\7z.exe' a $zipFilename $file | |
} | |
return $zipFilename | |
} | |
function MailZip-GitBanch($Recipient) { | |
if (!$Recipient) { | |
Write-Host "You need to pass the email of the recipient as parameter" | |
return | |
} | |
$branch = Get-GitBranch | |
$zipFilename = [string]::Format(".\{0}.zip", $branch) | |
$attachement = [IO.Path]::GetFullPath( $zipFilename ) | |
Zip-GitBranch($attachement) | |
$ol = New-Object -comObject Outlook.Application | |
$Mail = $ol.CreateItem(0) | |
$Mail.Recipients.Add($Recipient) | |
$Mail.Subject = "Changes for the branch: " + $branch | |
$Mail.Body = "Check out the email attachement to see the changes made to the branch: " + $branch | |
$Mail.Attachments.Add($attachement) | |
$Mail.Send() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment