t / t4204-patch-id.shon commit git.txt: remove stale comment regarding GIT_WORK_TREE (a758a34)
   1#!/bin/sh
   2
   3test_description='git patch-id'
   4
   5. ./test-lib.sh
   6
   7test_expect_success 'setup' '
   8        test_commit initial foo a &&
   9        test_commit first foo b &&
  10        git checkout -b same HEAD^ &&
  11        test_commit same-msg foo b &&
  12        git checkout -b notsame HEAD^ &&
  13        test_commit notsame-msg foo c
  14'
  15
  16test_expect_success 'patch-id output is well-formed' '
  17        git log -p -1 | git patch-id > output &&
  18        grep "^[a-f0-9]\{40\} $(git rev-parse HEAD)$" output
  19'
  20
  21calc_patch_id () {
  22        git patch-id |
  23                sed "s# .*##" > patch-id_"$1"
  24}
  25
  26get_patch_id () {
  27        git log -p -1 "$1" | git patch-id |
  28                sed "s# .*##" > patch-id_"$1"
  29}
  30
  31test_expect_success 'patch-id detects equality' '
  32        get_patch_id master &&
  33        get_patch_id same &&
  34        test_cmp patch-id_master patch-id_same
  35'
  36
  37test_expect_success 'patch-id detects inequality' '
  38        get_patch_id master &&
  39        get_patch_id notsame &&
  40        ! test_cmp patch-id_master patch-id_notsame
  41'
  42
  43test_expect_success 'patch-id supports git-format-patch output' '
  44        get_patch_id master &&
  45        git checkout same &&
  46        git format-patch -1 --stdout | calc_patch_id same &&
  47        test_cmp patch-id_master patch-id_same &&
  48        set `git format-patch -1 --stdout | git patch-id` &&
  49        test "$2" = `git rev-parse HEAD`
  50'
  51
  52test_expect_success 'whitespace is irrelevant in footer' '
  53        get_patch_id master &&
  54        git checkout same &&
  55        git format-patch -1 --stdout | sed "s/ \$//" | calc_patch_id same &&
  56        test_cmp patch-id_master patch-id_same
  57'
  58
  59test_expect_success 'patch-id supports git-format-patch MIME output' '
  60        get_patch_id master &&
  61        git checkout same &&
  62        git format-patch -1 --attach --stdout | calc_patch_id same &&
  63        test_cmp patch-id_master patch-id_same
  64'
  65
  66cat >nonl <<\EOF
  67diff --git i/a w/a
  68index e69de29..2e65efe 100644
  69--- i/a
  70+++ w/a
  71@@ -0,0 +1 @@
  72+a
  73\ No newline at end of file
  74diff --git i/b w/b
  75index e69de29..6178079 100644
  76--- i/b
  77+++ w/b
  78@@ -0,0 +1 @@
  79+b
  80EOF
  81
  82cat >withnl <<\EOF
  83diff --git i/a w/a
  84index e69de29..7898192 100644
  85--- i/a
  86+++ w/a
  87@@ -0,0 +1 @@
  88+a
  89diff --git i/b w/b
  90index e69de29..6178079 100644
  91--- i/b
  92+++ w/b
  93@@ -0,0 +1 @@
  94+b
  95EOF
  96
  97test_expect_success 'patch-id handles no-nl-at-eof markers' '
  98        cat nonl | calc_patch_id nonl &&
  99        cat withnl | calc_patch_id withnl &&
 100        test_cmp patch-id_nonl patch-id_withnl
 101'
 102test_done