t / t7509-commit.shon commit Introduce remove_or_warn function (80d706a)
   1#!/bin/sh
   2#
   3# Copyright (c) 2009 Erick Mattos
   4#
   5
   6test_description='git commit --reset-author'
   7
   8. ./test-lib.sh
   9
  10author_header () {
  11        git cat-file commit "$1" |
  12        sed -n -e '/^$/q' -e '/^author /p'
  13}
  14
  15message_body () {
  16        git cat-file commit "$1" |
  17        sed -e '1,/^$/d'
  18}
  19
  20test_expect_success '-C option copies authorship and message' '
  21        echo "Initial" >foo &&
  22        git add foo &&
  23        test_tick &&
  24        git commit -m "Initial Commit" --author Frigate\ \<flying@over.world\> &&
  25        git tag Initial &&
  26        echo "Test 1" >>foo &&
  27        test_tick &&
  28        git commit -a -C Initial &&
  29        author_header Initial >expect &&
  30        author_header HEAD >actual &&
  31        test_cmp expect actual &&
  32
  33        message_body Initial >expect &&
  34        message_body HEAD >actual &&
  35        test_cmp expect actual
  36'
  37
  38test_expect_success '-C option copies only the message with --reset-author' '
  39        echo "Test 2" >>foo &&
  40        test_tick &&
  41        git commit -a -C Initial --reset-author &&
  42        echo "author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE" >expect &&
  43        author_header HEAD >actual
  44        test_cmp expect actual &&
  45
  46        message_body Initial >expect &&
  47        message_body HEAD >actual &&
  48        test_cmp expect actual
  49'
  50
  51test_expect_success '-c option copies authorship and message' '
  52        echo "Test 3" >>foo &&
  53        test_tick &&
  54        EDITOR=: VISUAL=: git commit -a -c Initial &&
  55        author_header Initial >expect &&
  56        author_header HEAD >actual &&
  57        test_cmp expect actual
  58'
  59
  60test_expect_success '-c option copies only the message with --reset-author' '
  61        echo "Test 4" >>foo &&
  62        test_tick &&
  63        EDITOR=: VISUAL=: git commit -a -c Initial --reset-author &&
  64        echo "author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE" >expect &&
  65        author_header HEAD >actual &&
  66        test_cmp expect actual &&
  67
  68        message_body Initial >expect &&
  69        message_body HEAD >actual &&
  70        test_cmp expect actual
  71'
  72
  73test_expect_success '--amend option copies authorship' '
  74        git checkout Initial &&
  75        echo "Test 5" >>foo &&
  76        test_tick &&
  77        git commit -a --amend -m "amend test" &&
  78        author_header Initial >expect &&
  79        author_header HEAD >actual &&
  80
  81        echo "amend test" >expect &&
  82        message_body HEAD >actual &&
  83        test_cmp expect actual
  84'
  85
  86test_expect_success '--reset-author makes the commit ours even with --amend option' '
  87        git checkout Initial &&
  88        echo "Test 6" >>foo &&
  89        test_tick &&
  90        git commit -a --reset-author -m "Changed again" --amend &&
  91        echo "author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE" >expect &&
  92        author_header HEAD >actual &&
  93        test_cmp expect actual &&
  94
  95        echo "Changed again" >expect &&
  96        message_body HEAD >actual &&
  97        test_cmp expect actual
  98'
  99
 100test_expect_success '--reset-author and --author are mutually exclusive' '
 101        git checkout Initial &&
 102        echo "Test 7" >>foo &&
 103        test_tick &&
 104        test_must_fail git commit -a --reset-author --author="Xyzzy <frotz@nitfol.xz>"
 105'
 106
 107test_expect_success '--reset-author should be rejected without -c/-C/--amend' '
 108        git checkout Initial &&
 109        echo "Test 7" >>foo &&
 110        test_tick &&
 111        test_must_fail git commit -a --reset-author -m done
 112'
 113
 114test_done