#!/bin/sh global test_description := ''git rebase - test patch id computation'' source ./test-lib.sh proc count { global i := '0' while test $i -lt $1 { echo $i global i := $($i+1) } } proc scramble { global i := '0' while read x { if test $i -ne 0 { echo $x } global i := $(($i+1) % 10) } <"$1" >"$1.new" mv -f "$1.new" $1 } proc run { echo '$' @Argv /usr/bin/time @Argv >/dev/null } test_expect_success 'setup' ' git commit --allow-empty -m initial && git tag root ' proc do_tests { global nlines := $1, pr := $(2-) test_expect_success $pr "setup: $nlines lines" " rm -f .gitattributes && git checkout -q -f master && git reset --hard root && count $nlines >file && git add file && git commit -q -m initial && git branch -f other && scramble file && git add file && git commit -q -m 'change big file' && git checkout -q other && : >newfile && git add newfile && git commit -q -m 'add small file' && git cherry-pick master >/dev/null 2>&1 " test_debug " run git diff master^\! " test_expect_success $pr 'setup attributes' " echo 'file binary' >.gitattributes " test_debug " run git format-patch --stdout master && run git format-patch --stdout --ignore-if-in-upstream master " test_expect_success $pr 'detect upstream patch' ' git checkout -q master && scramble file && git add file && git commit -q -m "change big file again" && git checkout -q other^{} && git rebase master && test_must_fail test -n "$(git rev-list master...HEAD~)" ' test_expect_success $pr 'do not drop patch' ' git branch -f squashed master && git checkout -q -f squashed && git reset -q --soft HEAD~2 && git commit -q -m squashed && git checkout -q other^{} && test_must_fail git rebase squashed && rm -rf .git/rebase-apply ' } do_tests 500 do_tests 50000 EXPENSIVE test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"git rebase - test patch id computation">)} spids: [4] ) ] spids: [4] ) (C {(.)} {(./test-lib.sh)}) (FuncDef name: count body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:i) op:Equal rhs:{(0)} spids:[23])] spids: [23] ) (While cond: [(C {(test)} {($ VSub_Name "$i")} {(-lt)} {($ VSub_Number "$1")})] body: (DoGroup children: [ (C {(echo)} {(DQ ($ VSub_Name "$i"))}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:i) op: Equal rhs: { (ArithSubPart anode: (ArithBinary op_id: Arith_Plus left: (ArithWord w:{($ VSub_Name "$i")}) right: (ArithWord w:{(Lit_Digits 1)}) ) spids: [49 54] ) } spids: [48] ) ] spids: [48] ) ] spids: [38 57] ) ) ] spids: [20] ) spids: [15 19] ) (FuncDef name: scramble body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:i) op:Equal rhs:{(0)} spids:[70])] spids: [70] ) (While cond: [(C {(read)} {(x)})] body: (DoGroup children: [ (If arms: [ (if_arm cond: [(C {(test)} {($ VSub_Name "$i")} {(-ne)} {(0)})] action: [(C {(echo)} {(DQ ($ VSub_Name "$x"))})] spids: [-1 95] ) ] spids: [-1 105] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:i) op: Equal rhs: { (ArithSubPart anode: (ArithBinary op_id: Arith_Percent left: (ArithBinary op_id: Arith_Plus left: (ArithWord w:{($ VSub_Name "$i")}) right: (ArithWord w:{(Lit_Digits 1)}) ) right: (ArithWord w:{(Lit_Digits 10)}) ) spids: [109 120] ) } spids: [108] ) ] spids: [108] ) ] spids: [81 123] ) redirects: [ (Redir op_id: Redir_Less fd: -1 arg_word: {(DQ ($ VSub_Number "$1"))} spids: [125] ) (Redir op_id: Redir_Great fd: -1 arg_word: {(DQ ($ VSub_Number "$1") (.new))} spids: [130] ) ] ) (C {(mv)} {(-f)} {(DQ ($ VSub_Number "$1") (.new))} {(DQ ($ VSub_Number "$1"))}) ] spids: [67] ) spids: [62 66] ) (FuncDef name: run body: (BraceGroup children: [ (C {(echo)} {(EscapedLiteralPart token:)} {(DQ ($ VSub_At "$@"))}) (SimpleCommand words: [{(/usr/bin/time)} {(DQ ($ VSub_At "$@"))}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[176])] ) ] spids: [158] ) spids: [153 157] ) (C {(test_expect_success)} {(SQ )} {(SQ <"\n"> <"\tgit commit --allow-empty -m initial &&\n"> <"\tgit tag root\n">)} ) (FuncDef name: do_tests body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:nlines) op: Equal rhs: {($ VSub_Number "$1")} spids: [203] ) (assign_pair lhs: (LhsName name:pr) op: Equal rhs: { (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_Hyphen arg_word:{}) spids: [207 210] ) } spids: [206] ) ] spids: [203] ) (C {(test_expect_success)} {($ VSub_Name "$pr")} {(DQ ("setup: ") ($ VSub_Name "$nlines") (" lines"))} { (DQ ("\n") ("\t\trm -f .gitattributes &&\n") ("\t\tgit checkout -q -f master &&\n") ("\t\tgit reset --hard root &&\n") ("\t\tcount ") ($ VSub_Name "$nlines") (" >file &&\n") ("\t\tgit add file &&\n") ("\t\tgit commit -q -m initial &&\n") ("\t\tgit branch -f other &&\n") ("\n") ("\t\tscramble file &&\n") ("\t\tgit add file &&\n") ("\t\tgit commit -q -m 'change big file' &&\n") ("\n") ("\t\tgit checkout -q other &&\n") ("\t\t: >newfile &&\n") ("\t\tgit add newfile &&\n") ("\t\tgit commit -q -m 'add small file' &&\n") ("\n") ("\t\tgit cherry-pick master >/dev/null 2>&1\n") ("\t") ) } ) (C {(test_debug)} { (DQ ("\n") ("\t\trun git diff master^") (EscapedLiteralPart token:) ("\n") ("\t") ) } ) (C {(test_expect_success)} {($ VSub_Name "$pr")} {(SQ <"setup attributes">)} {(DQ ("\n") ("\t\techo 'file binary' >.gitattributes\n") ("\t"))} ) (C {(test_debug)} { (DQ ("\n") ("\t\trun git format-patch --stdout master &&\n") ("\t\trun git format-patch --stdout --ignore-if-in-upstream master\n") ("\t") ) } ) (C {(test_expect_success)} {($ VSub_Name "$pr")} {(SQ <"detect upstream patch">)} { (SQ <"\n"> <"\t\tgit checkout -q master &&\n"> <"\t\tscramble file &&\n"> <"\t\tgit add file &&\n"> <"\t\tgit commit -q -m \"change big file again\" &&\n"> <"\t\tgit checkout -q other^{} &&\n"> <"\t\tgit rebase master &&\n"> <"\t\ttest_must_fail test -n \"$(git rev-list master...HEAD~)\"\n"> <"\t"> ) } ) (C {(test_expect_success)} {($ VSub_Name "$pr")} {(SQ <"do not drop patch">)} { (SQ <"\n"> <"\t\tgit branch -f squashed master &&\n"> <"\t\tgit checkout -q -f squashed &&\n"> <"\t\tgit reset -q --soft HEAD~2 &&\n"> <"\t\tgit commit -q -m squashed &&\n"> <"\t\tgit checkout -q other^{} &&\n"> <"\t\ttest_must_fail git rebase squashed &&\n"> <"\t\trm -rf .git/rebase-apply\n"> <"\t"> ) } ) ] spids: [200] ) spids: [195 199] ) (C {(do_tests)} {(500)}) (C {(do_tests)} {(50000)} {(EXPENSIVE)}) (C {(test_done)}) ] )