Skip to content

Instantly share code, notes, and snippets.

@laurentkempe
Created April 12, 2012 22:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laurentkempe/2371417 to your computer and use it in GitHub Desktop.
Save laurentkempe/2371417 to your computer and use it in GitHub Desktop.
Sending your Git branch changes as an email attachment
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