#!/bin/sh # # Copyright (c) 2009 Erick Mattos # global test_description := ''git commit --reset-author'' source ./test-lib.sh proc author_header { git cat-file commit $1 | sed -n -e '/^$/q' -e '/^author /p' } proc message_body { git cat-file commit $1 | sed -e '1,/^$/d' } test_expect_success '-C option copies authorship and message' ' echo "Initial" >foo && git add foo && test_tick && git commit -m "Initial Commit" --author Frigate\ \ && git tag Initial && echo "Test 1" >>foo && test_tick && git commit -a -C Initial && author_header Initial >expect && author_header HEAD >actual && test_cmp expect actual && message_body Initial >expect && message_body HEAD >actual && test_cmp expect actual ' test_expect_success '-C option copies only the message with --reset-author' ' echo "Test 2" >>foo && test_tick && git commit -a -C Initial --reset-author && echo "author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE" >expect && author_header HEAD >actual && test_cmp expect actual && message_body Initial >expect && message_body HEAD >actual && test_cmp expect actual ' test_expect_success '-c option copies authorship and message' ' echo "Test 3" >>foo && test_tick && EDITOR=: VISUAL=: git commit -a -c Initial && author_header Initial >expect && author_header HEAD >actual && test_cmp expect actual ' test_expect_success '-c option copies only the message with --reset-author' ' echo "Test 4" >>foo && test_tick && EDITOR=: VISUAL=: git commit -a -c Initial --reset-author && echo "author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE" >expect && author_header HEAD >actual && test_cmp expect actual && message_body Initial >expect && message_body HEAD >actual && test_cmp expect actual ' test_expect_success '--amend option copies authorship' ' git checkout Initial && echo "Test 5" >>foo && test_tick && git commit -a --amend -m "amend test" && author_header Initial >expect && author_header HEAD >actual && test_cmp expect actual && echo "amend test" >expect && message_body HEAD >actual && test_cmp expect actual ' proc sha1_file { echo "$ifsjoin(Argv)" | sed "s#..#.git/objects/&/#" } proc remove_object { rm -f $[sha1_file "$ifsjoin(Argv)] } test_expect_success '--amend option with empty author' ' git cat-file commit Initial >tmp && sed "s/author [^<]* empty-author && sha=$(git hash-object -t commit -w empty-author) && test_when_finished "remove_object $sha" && git checkout $sha && test_when_finished "git checkout Initial" && echo "Empty author test" >>foo && test_tick && test_must_fail git commit -a -m "empty author" --amend 2>err && grep "empty ident" err ' test_expect_success '--amend option with missing author' ' git cat-file commit Initial >tmp && sed "s/author [^<]* malformed && sha=$(git hash-object -t commit -w malformed) && test_when_finished "remove_object $sha" && git checkout $sha && test_when_finished "git checkout Initial" && echo "Missing author test" >>foo && test_tick && test_must_fail git commit -a -m "malformed author" --amend 2>err && grep "empty ident" err ' test_expect_success '--reset-author makes the commit ours even with --amend option' ' git checkout Initial && echo "Test 6" >>foo && test_tick && git commit -a --reset-author -m "Changed again" --amend && echo "author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE" >expect && author_header HEAD >actual && test_cmp expect actual && echo "Changed again" >expect && message_body HEAD >actual && test_cmp expect actual ' test_expect_success '--reset-author and --author are mutually exclusive' ' git checkout Initial && echo "Test 7" >>foo && test_tick && test_must_fail git commit -a --reset-author --author="Xyzzy " ' test_expect_success '--reset-author should be rejected without -c/-C/--amend' ' git checkout Initial && echo "Test 7" >>foo && test_tick && test_must_fail git commit -a --reset-author -m done ' test_expect_success 'commit respects CHERRY_PICK_HEAD and MERGE_MSG' ' echo "cherry-pick 1a" >>foo && test_tick && git commit -am "cherry-pick 1" --author="Cherry " && git tag cherry-pick-head && git rev-parse cherry-pick-head >.git/CHERRY_PICK_HEAD && echo "This is a MERGE_MSG" >.git/MERGE_MSG && echo "cherry-pick 1b" >>foo && test_tick && git commit -a && author_header cherry-pick-head >expect && author_header HEAD >actual && test_cmp expect actual && echo "This is a MERGE_MSG" >expect && message_body HEAD >actual && test_cmp expect actual ' test_expect_success '--reset-author with CHERRY_PICK_HEAD' ' git rev-parse cherry-pick-head >.git/CHERRY_PICK_HEAD && echo "cherry-pick 2" >>foo && test_tick && git commit -am "cherry-pick 2" --reset-author && echo "author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE" >expect && author_header HEAD >actual && test_cmp expect actual ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"git commit --reset-author">)} spids: [13] ) ] spids: [13] ) (C {(.)} {(./test-lib.sh)}) (FuncDef name: author_header body: (BraceGroup children: [ (Pipeline children: [ (C {(git)} {(cat-file)} {(commit)} {(DQ ($ VSub_Number "$1"))}) (C {(sed)} {(-n)} {(-e)} {(SQ <"/^$/q">)} {(-e)} {(SQ <"/^author /p">)}) ] negated: False ) ] spids: [29] ) spids: [24 28] ) (FuncDef name: message_body body: (BraceGroup children: [ (Pipeline children: [ (C {(git)} {(cat-file)} {(commit)} {(DQ ($ VSub_Number "$1"))}) (C {(sed)} {(-e)} {(SQ <"1,/^$/d">)}) ] negated: False ) ] spids: [69] ) spids: [64 68] ) (C {(test_expect_success)} {(SQ <"-C option copies authorship and message">)} { (SQ <"\n"> <"\techo \"Initial\" >foo &&\n"> <"\tgit add foo &&\n"> <"\ttest_tick &&\n"> <"\tgit commit -m \"Initial Commit\" --author Frigate\\ \\ &&\n"> <"\tgit tag Initial &&\n"> <"\techo \"Test 1\" >>foo &&\n"> <"\ttest_tick &&\n"> <"\tgit commit -a -C Initial &&\n"> <"\tauthor_header Initial >expect &&\n"> <"\tauthor_header HEAD >actual &&\n"> <"\ttest_cmp expect actual &&\n"> <"\n"> <"\tmessage_body Initial >expect &&\n"> <"\tmessage_body HEAD >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"-C option copies only the message with --reset-author">)} { (SQ <"\n"> <"\techo \"Test 2\" >>foo &&\n"> <"\ttest_tick &&\n"> <"\tgit commit -a -C Initial --reset-author &&\n"> <"\techo \"author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE\" >expect &&\n"> <"\tauthor_header HEAD >actual &&\n"> <"\ttest_cmp expect actual &&\n"> <"\n"> <"\tmessage_body Initial >expect &&\n"> <"\tmessage_body HEAD >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"-c option copies authorship and message">)} { (SQ <"\n"> <"\techo \"Test 3\" >>foo &&\n"> <"\ttest_tick &&\n"> <"\tEDITOR=: VISUAL=: git commit -a -c Initial &&\n"> <"\tauthor_header Initial >expect &&\n"> <"\tauthor_header HEAD >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"-c option copies only the message with --reset-author">)} { (SQ <"\n"> <"\techo \"Test 4\" >>foo &&\n"> <"\ttest_tick &&\n"> <"\tEDITOR=: VISUAL=: git commit -a -c Initial --reset-author &&\n"> <"\techo \"author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE\" >expect &&\n"> <"\tauthor_header HEAD >actual &&\n"> <"\ttest_cmp expect actual &&\n"> <"\n"> <"\tmessage_body Initial >expect &&\n"> <"\tmessage_body HEAD >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"--amend option copies authorship">)} { (SQ <"\n"> <"\tgit checkout Initial &&\n"> <"\techo \"Test 5\" >>foo &&\n"> <"\ttest_tick &&\n"> <"\tgit commit -a --amend -m \"amend test\" &&\n"> <"\tauthor_header Initial >expect &&\n"> <"\tauthor_header HEAD >actual &&\n"> <"\ttest_cmp expect actual &&\n"> <"\n"> <"\techo \"amend test\" >expect &&\n"> <"\tmessage_body HEAD >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (FuncDef name: sha1_file body: (BraceGroup children: [ (Pipeline children: [ (C {(echo)} {(DQ ($ VSub_Star "$*"))}) (C {(sed)} {(DQ ("s#..#.git/objects/&/#"))}) ] negated: False ) ] spids: [207] ) spids: [203 206] ) (FuncDef name: remove_object body: (BraceGroup children: [ (C {(rm)} {(-f)} { (CommandSubPart command_list: (CommandList children:[(C {(sha1_file)} {(DQ ($ VSub_Star "$*"))})]) left_token: spids: [237 243] ) } ) ] spids: [230] ) spids: [226 229] ) (C {(test_expect_success)} {(SQ <"--amend option with empty author">)} { (SQ <"\n"> <"\tgit cat-file commit Initial >tmp &&\n"> <"\tsed \"s/author [^<]* empty-author &&\n"> <"\tsha=$(git hash-object -t commit -w empty-author) &&\n"> <"\ttest_when_finished \"remove_object $sha\" &&\n"> <"\tgit checkout $sha &&\n"> <"\ttest_when_finished \"git checkout Initial\" &&\n"> <"\techo \"Empty author test\" >>foo &&\n"> <"\ttest_tick &&\n"> <"\ttest_must_fail git commit -a -m \"empty author\" --amend 2>err &&\n"> <"\tgrep \"empty ident\" err\n"> ) } ) (C {(test_expect_success)} {(SQ <"--amend option with missing author">)} { (SQ <"\n"> <"\tgit cat-file commit Initial >tmp &&\n"> <"\tsed \"s/author [^<]* malformed &&\n"> <"\tsha=$(git hash-object -t commit -w malformed) &&\n"> <"\ttest_when_finished \"remove_object $sha\" &&\n"> <"\tgit checkout $sha &&\n"> <"\ttest_when_finished \"git checkout Initial\" &&\n"> <"\techo \"Missing author test\" >>foo &&\n"> <"\ttest_tick &&\n"> <"\ttest_must_fail git commit -a -m \"malformed author\" --amend 2>err &&\n"> <"\tgrep \"empty ident\" err\n"> ) } ) (C {(test_expect_success)} {(SQ <"--reset-author makes the commit ours even with --amend option">)} { (SQ <"\n"> <"\tgit checkout Initial &&\n"> <"\techo \"Test 6\" >>foo &&\n"> <"\ttest_tick &&\n"> <"\tgit commit -a --reset-author -m \"Changed again\" --amend &&\n"> <"\techo \"author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE\" >expect &&\n"> <"\tauthor_header HEAD >actual &&\n"> <"\ttest_cmp expect actual &&\n"> <"\n"> <"\techo \"Changed again\" >expect &&\n"> <"\tmessage_body HEAD >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"--reset-author and --author are mutually exclusive">)} { (SQ <"\n"> <"\tgit checkout Initial &&\n"> <"\techo \"Test 7\" >>foo &&\n"> <"\ttest_tick &&\n"> <"\ttest_must_fail git commit -a --reset-author --author=\"Xyzzy \"\n"> ) } ) (C {(test_expect_success)} {(SQ <"--reset-author should be rejected without -c/-C/--amend">)} { (SQ <"\n"> <"\tgit checkout Initial &&\n"> <"\techo \"Test 7\" >>foo &&\n"> <"\ttest_tick &&\n"> <"\ttest_must_fail git commit -a --reset-author -m done\n"> ) } ) (C {(test_expect_success)} {(SQ <"commit respects CHERRY_PICK_HEAD and MERGE_MSG">)} { (SQ <"\n"> <"\techo \"cherry-pick 1a\" >>foo &&\n"> <"\ttest_tick &&\n"> <"\tgit commit -am \"cherry-pick 1\" --author=\"Cherry \" &&\n"> <"\tgit tag cherry-pick-head &&\n"> <"\tgit rev-parse cherry-pick-head >.git/CHERRY_PICK_HEAD &&\n"> <"\techo \"This is a MERGE_MSG\" >.git/MERGE_MSG &&\n"> <"\techo \"cherry-pick 1b\" >>foo &&\n"> <"\ttest_tick &&\n"> <"\tgit commit -a &&\n"> <"\tauthor_header cherry-pick-head >expect &&\n"> <"\tauthor_header HEAD >actual &&\n"> <"\ttest_cmp expect actual &&\n"> <"\n"> <"\techo \"This is a MERGE_MSG\" >expect &&\n"> <"\tmessage_body HEAD >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"--reset-author with CHERRY_PICK_HEAD">)} { (SQ <"\n"> <"\tgit rev-parse cherry-pick-head >.git/CHERRY_PICK_HEAD &&\n"> <"\techo \"cherry-pick 2\" >>foo &&\n"> <"\ttest_tick &&\n"> <"\tgit commit -am \"cherry-pick 2\" --reset-author &&\n"> <"\techo \"author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE\" >expect &&\n"> <"\tauthor_header HEAD >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_done)}) ] )