Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. $ErrorActionPreference = "Stop"
  2.  
  3. function Main {
  4. "This script creates a zip file that contains all files changed between two commits."
  5. "Commits can be specified as commit IDs (SHA) or as branch names."
  6. "For example: 'master' or 'ff39683ed6'"
  7. ""
  8.  
  9. $git_dir = Read-Host -Prompt "Git directory"
  10. $to_commit = Read-Host -Prompt "Commit to deploy"
  11. $from_commit = Read-Host -Prompt "Previously deployed commit"
  12.  
  13. pushd $git_dir
  14. try {
  15. $datestr = "{0:yyMMdd-HHmmss}" -f (get-date)
  16. $export_filename = "export_$datestr.zip"
  17.  
  18. # All files that have been changed, excluding deleted files
  19. $changed_files = git diff --name-only "$from_commit" "$to_commit" --diff-filter=d
  20.  
  21. # Deleted files, for listing
  22. $deleted_files = git diff --name-only "$from_commit" "$to_commit" --diff-filter=D
  23.  
  24. # Create the export
  25. git archive --output="$export_filename" $to_commit $changed_files
  26.  
  27. ""
  28. "Created $export_filename in $git_dir"
  29.  
  30. if ($deleted_files) {
  31. "Deleted files:"
  32. foreach ($filename in $deleted_files) {
  33. " - $filename"
  34. }
  35. }
  36.  
  37. } finally {
  38. popd
  39. }
  40. }
  41.  
  42. Main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement