Skip to content

Instantly share code, notes, and snippets.

@adriancampos
Last active August 1, 2023 02:51
Show Gist options
  • Save adriancampos/36945d04b21a2068f2facc54344b4f9c to your computer and use it in GitHub Desktop.
Save adriancampos/36945d04b21a2068f2facc54344b4f9c to your computer and use it in GitHub Desktop.

Revisions

  1. adriancampos renamed this gist Feb 22, 2019. 1 changed file with 0 additions and 0 deletions.
  2. adriancampos renamed this gist Feb 22, 2019. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. adriancampos renamed this gist Feb 22, 2019. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. adriancampos revised this gist Feb 22, 2019. 1 changed file with 9 additions and 11 deletions.
    20 changes: 9 additions & 11 deletions createarchive.ps1
    Original file line number Diff line number Diff line change
    @@ -1,31 +1,29 @@
    param([String]$commit="HEAD", [String]$secondcommit="$commit^")
    param([String]$firstcommit="HEAD", [String]$secondcommit="$firstcommit^")

    echo $commit
    echo $secondcommit

    $singlecommit = $secondcommit -eq "${commit}^"
    $singlecommit = $secondcommit -eq "${firstcommit}^"


    # get commit hash from name. Used for naming the zip.
    $commit = $(git rev-parse --short --verify $commit)
    $firstcommit = $(git rev-parse --short --verify $firstcommit)
    $secondcommit = $(git rev-parse --short --verify $secondcommit)


    $outpath = "${commit}"
    $outpath = "${firstcommit}"
    if (!$singlecommit) {
    $outpath += "_${secondcommit}"
    }


    echo "Diff ${commit}...${secondcommit}"
    echo "Diff ${firstcommit}...${secondcommit}"

    echo "Changed files:"
    echo $(git diff --name-only $commit $secondcommit)
    echo $(git diff --name-only $firstcommit $secondcommit)
    echo $(git diff --name-only $firstcommit $secondcommit) >> "${outpath}.txt"

    # create flattened archive
    Compress-Archive -Force -DestinationPath "${outpath}_flat.zip" -Path $(git diff --name-only $commit $secondcommit)
    Compress-Archive -Force -DestinationPath "${outpath}_flat.zip" -Path $(git diff --name-only $firstcommit $secondcommit)

    # create structured archive
    git archive -o "${outpath}.zip" $commit $(git diff --name-only $commit $secondcommit)
    git archive -o "${outpath}.zip" $firstcommit $(git diff --name-only $firstcommit $secondcommit)

    echo "Created $outpath"
  5. adriancampos revised this gist Feb 22, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    #Usage:
    # Usage:

    `.\createarchive.ps1`

  6. adriancampos revised this gist Feb 22, 2019. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,13 @@
    Usage:
    #Usage:

    `.\createarchive.ps1`

    Creates an archive of the files that changed between HEAD and HEAD^

    `.\createarchive.ps1 e39eef`

    Creates an archive of the files that changed between e39eef and e39eef^

    `.\createarchive.ps1 e39eef 1e4bf3`

    Creates an archive of the files that changed between e39eef and 1e4bf3^
  7. adriancampos revised this gist Feb 22, 2019. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    Usage:

    `.\createarchive.ps1`
    Creates an archive of the files that changed between HEAD and HEAD^

  8. adriancampos created this gist Feb 22, 2019.
    9 changes: 9 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    Usage:
    `.\createarchive.ps1`
    Creates an archive of the files that changed between HEAD and HEAD^

    `.\createarchive.ps1 e39eef`
    Creates an archive of the files that changed between e39eef and e39eef^

    `.\createarchive.ps1 e39eef 1e4bf3`
    Creates an archive of the files that changed between e39eef and 1e4bf3^
    31 changes: 31 additions & 0 deletions createarchive.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    param([String]$commit="HEAD", [String]$secondcommit="$commit^")

    echo $commit
    echo $secondcommit

    $singlecommit = $secondcommit -eq "${commit}^"


    # get commit hash from name. Used for naming the zip.
    $commit = $(git rev-parse --short --verify $commit)
    $secondcommit = $(git rev-parse --short --verify $secondcommit)


    $outpath = "${commit}"
    if (!$singlecommit) {
    $outpath += "_${secondcommit}"
    }


    echo "Diff ${commit}...${secondcommit}"

    echo "Changed files:"
    echo $(git diff --name-only $commit $secondcommit)

    # create flattened archive
    Compress-Archive -Force -DestinationPath "${outpath}_flat.zip" -Path $(git diff --name-only $commit $secondcommit)

    # create structured archive
    git archive -o "${outpath}.zip" $commit $(git diff --name-only $commit $secondcommit)

    echo "Created $outpath"