#!/bin/sh global test_description := ''merge simplification'' source ./test-lib.sh proc note { git tag $1 } proc unnote { git name-rev --tags --stdin | sed -e "s|$_x40 (tags/\([^)]*\)) |\1 |g" } test_expect_success setup ' echo "Hi there" >file && echo "initial" >lost && git add file lost && test_tick && git commit -m "Initial file and lost" && note A && git branch other-branch && echo "Hello" >file && echo "second" >lost && git add file lost && test_tick && git commit -m "Modified file and lost" && note B && git checkout other-branch && echo "Hello" >file && >lost && git add file lost && test_tick && git commit -m "Modified the file identically" && note C && echo "This is a stupid example" >another-file && git add another-file && test_tick && git commit -m "Add another file" && note D && test_tick && test_must_fail git merge -m "merge" master && >lost && git commit -a -m "merge" && note E && echo "Yet another" >elif && git add elif && test_tick && git commit -m "Irrelevant change" && note F && git checkout master && echo "Yet another" >elif && git add elif && test_tick && git commit -m "Another irrelevant change" && note G && test_tick && git merge -m "merge" other-branch && note H && echo "Final change" >file && test_tick && git commit -a -m "Final change" && note I && git symbolic-ref HEAD refs/heads/unrelated && git rm -f "*" && echo "Unrelated branch" >side && git add side && test_tick && git commit -m "Side root" && note J && git checkout master && test_tick && git merge --allow-unrelated-histories -m "Coolest" unrelated && note K && echo "Immaterial" >elif && git add elif && test_tick && git commit -m "Last" && note L ' global FMT := ''tformat:%P %H | %s'' proc check_outcome { global outcome := $1 shift for c in [$1] { echo $c } >expect && shift && global param := "$ifsjoin(Argv)" && test_expect_$outcome "log $param" ' git log --pretty="$FMT" --parents $param | unnote >actual && sed -e "s/^.* \([^ ]*\) .*/\1/" >check expect && git log --pretty="$FMT" --full-history E -- lost | unnote >actual && sed -e "s/^.* \([^ ]*\) .*/\1/" >check expected && git log -p --pretty="%H" --full-diff --parents -- file >actual && test_cmp expected actual ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"merge simplification">)} spids: [4] ) ] spids: [4] ) (C {(.)} {(./test-lib.sh)}) (FuncDef name: note body: (BraceGroup children:[(C {(git)} {(tag)} {(DQ ($ VSub_Number "$1"))})] spids:[20]) spids: [15 19] ) (FuncDef name: unnote body: (BraceGroup children: [ (Pipeline children: [ (C {(git)} {(name-rev)} {(--tags)} {(--stdin)}) (C {(sed)} {(-e)} { (DQ ("s|") ($ VSub_Name "$_x40") (" (tags/") (EscapedLiteralPart token:) ("[^)]*") (EscapedLiteralPart token:) (") |") (EscapedLiteralPart token:) (" |g") ) } ) ] negated: False ) ] spids: [39] ) spids: [34 38] ) (C {(test_expect_success)} {(setup)} { (SQ <"\n"> <"\techo \"Hi there\" >file &&\n"> <"\techo \"initial\" >lost &&\n"> <"\tgit add file lost &&\n"> <"\ttest_tick && git commit -m \"Initial file and lost\" &&\n"> <"\tnote A &&\n"> <"\n"> <"\tgit branch other-branch &&\n"> <"\n"> <"\techo \"Hello\" >file &&\n"> <"\techo \"second\" >lost &&\n"> <"\tgit add file lost &&\n"> <"\ttest_tick && git commit -m \"Modified file and lost\" &&\n"> <"\tnote B &&\n"> <"\n"> <"\tgit checkout other-branch &&\n"> <"\n"> <"\techo \"Hello\" >file &&\n"> <"\t>lost &&\n"> <"\tgit add file lost &&\n"> <"\ttest_tick && git commit -m \"Modified the file identically\" &&\n"> <"\tnote C &&\n"> <"\n"> <"\techo \"This is a stupid example\" >another-file &&\n"> <"\tgit add another-file &&\n"> <"\ttest_tick && git commit -m \"Add another file\" &&\n"> <"\tnote D &&\n"> <"\n"> <"\ttest_tick &&\n"> <"\ttest_must_fail git merge -m \"merge\" master &&\n"> <"\t>lost && git commit -a -m \"merge\" &&\n"> <"\tnote E &&\n"> <"\n"> <"\techo \"Yet another\" >elif &&\n"> <"\tgit add elif &&\n"> <"\ttest_tick && git commit -m \"Irrelevant change\" &&\n"> <"\tnote F &&\n"> <"\n"> <"\tgit checkout master &&\n"> <"\techo \"Yet another\" >elif &&\n"> <"\tgit add elif &&\n"> <"\ttest_tick && git commit -m \"Another irrelevant change\" &&\n"> <"\tnote G &&\n"> <"\n"> <"\ttest_tick && git merge -m \"merge\" other-branch &&\n"> <"\tnote H &&\n"> <"\n"> <"\techo \"Final change\" >file &&\n"> <"\ttest_tick && git commit -a -m \"Final change\" &&\n"> <"\tnote I &&\n"> <"\n"> <"\tgit symbolic-ref HEAD refs/heads/unrelated &&\n"> <"\tgit rm -f \"*\" &&\n"> <"\techo \"Unrelated branch\" >side &&\n"> <"\tgit add side &&\n"> <"\ttest_tick && git commit -m \"Side root\" &&\n"> <"\tnote J &&\n"> <"\n"> <"\tgit checkout master &&\n"> <"\ttest_tick && git merge --allow-unrelated-histories -m \"Coolest\" unrelated &&\n"> <"\tnote K &&\n"> <"\n"> <"\techo \"Immaterial\" >elif &&\n"> <"\tgit add elif &&\n"> <"\ttest_tick && git commit -m \"Last\" &&\n"> <"\tnote L\n"> ) } ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:FMT) op: Equal rhs: {(SQ <"tformat:%P \t%H | %s">)} spids: [145] ) ] spids: [145] ) (FuncDef name: check_outcome body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:outcome) op: Equal rhs: {($ VSub_Number "$1")} spids: [159] ) ] spids: [159] ) (C {(shift)}) (AndOr children: [ (ForEach iter_name: c iter_words: [{($ VSub_Number "$1")}] do_arg_iter: False body: (DoGroup children:[(C {(echo)} {(DQ ($ VSub_Name "$c"))})] spids:[175185]) redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(expect)} spids:[187])] spids: [171 -1] ) (AndOr children: [ (C {(shift)}) (AndOr children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:param) op: Equal rhs: {(DQ ($ VSub_Star "$*"))} spids: [198] ) ] spids: [198] ) (C {(test_expect_) ($ VSub_Name "$outcome")} {(DQ ("log ") ($ VSub_Name "$param"))} { (SQ <"\n"> <"\t\tgit log --pretty=\"$FMT\" --parents $param |\n"> <"\t\tunnote >actual &&\n"> <"\t\tsed -e \"s/^.*\t\\([^ ]*\\) .*/\\1/\" >check <"\t\ttest_cmp expect check\n"> <"\t"> ) } ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] spids: [156] ) spids: [151 155] ) (FuncDef name: check_result body: (BraceGroup children: [(C {(check_outcome)} {(success)} {(DQ ($ VSub_At "$@"))})] spids: [231] ) spids: [226 230] ) (C {(check_result)} {(SQ <"L K J I H G F E D C B A">)} {(--full-history)}) (C {(check_result)} {(SQ <"K I H E C B A">)} {(--full-history)} {(--)} {(file)}) (C {(check_result)} {(SQ <"K I H E C B A">)} {(--full-history)} {(--topo-order)} {(--)} {(file)}) (C {(check_result)} {(SQ <"K I H E C B A">)} {(--full-history)} {(--date-order)} {(--)} {(file)}) (C {(check_result)} {(SQ <"I E C B A">)} {(--simplify-merges)} {(--)} {(file)}) (C {(check_result)} {(SQ <"I B A">)} {(--)} {(file)}) (C {(check_result)} {(SQ <"I B A">)} {(--topo-order)} {(--)} {(file)}) (C {(check_result)} {(SQ )} {(--first-parent)} {(--)} {(another-file)}) (C {(check_result)} {(SQ <"E C B A">)} {(--full-history)} {(E)} {(--)} {(lost)}) (C {(test_expect_success)} {(SQ <"full history simplification without parent">)} { (SQ <"\n"> <"\tprintf \"%s\\n\" E C B A >expect &&\n"> <"\tgit log --pretty=\"$FMT\" --full-history E -- lost |\n"> <"\tunnote >actual &&\n"> <"\tsed -e \"s/^.*\t\\([^ ]*\\) .*/\\1/\" >check <"\ttest_cmp expect check\n"> ) } ) (C {(test_expect_success)} {(SQ <"--full-diff is not affected by --parents">)} { (SQ <"\n"> <"\tgit log -p --pretty=\"%H\" --full-diff -- file >expected &&\n"> <"\tgit log -p --pretty=\"%H\" --full-diff --parents -- file >actual &&\n"> <"\ttest_cmp expected actual\n"> ) } ) (C {(test_done)}) ] )