There exist three groups of tests which have repetitive lines of code. Introduce two functions test_rebase_autostash() and test_rebase_no_autostash() to reduce the number of lines. Also introduce loops to futher reduce the current implementation. Helped-by: Eric Sunshine <sunshine@xxxxxxxxxxxxxx> Signed-off-by: Mehul Jain <mehul.jain2029@xxxxxxxxx> --- t/t5520-pull.sh | 100 +++++++++++++++++++++++--------------------------------- 1 file changed, 41 insertions(+), 59 deletions(-) diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh index d03cb84..2611170 100755 --- a/t/t5520-pull.sh +++ b/t/t5520-pull.sh @@ -9,6 +9,24 @@ modify () { mv "$2.x" "$2" } +test_rebase_autostash () { + git reset --hard before-rebase && + echo dirty >new_file && + git add new_file && + git pull --rebase --autostash . copy && + test_cmp_rev HEAD^ copy && + test "$(cat new_file)" = dirty && + test "$(cat file)" = "modified again" +} + +test_rebase_no_autostash () { + git reset --hard before-rebase && + echo dirty >new_file && + git add new_file && + test_must_fail git pull --rebase --no-autostash . copy 2>err && + test_i18ngrep "Cannot pull with rebase: Your index contains uncommitted changes." err +} + test_expect_success setup ' echo file >file && git add file && @@ -256,75 +274,39 @@ test_expect_success 'pull --rebase succeeds with dirty working directory and reb test "$(cat file)" = "modified again" ' -test_expect_success 'pull --rebase --autostash & rebase.autostash=true' ' - test_config rebase.autostash true && - git reset --hard before-rebase && - echo dirty >new_file && - git add new_file && - git pull --rebase --autostash . copy && - test_cmp_rev HEAD^ copy && - test "$(cat new_file)" = dirty && - test "$(cat file)" = "modified again" -' - -test_expect_success 'pull --rebase --autostash & rebase.autostash=false' ' - test_config rebase.autostash false && - git reset --hard before-rebase && - echo dirty >new_file && - git add new_file && - git pull --rebase --autostash . copy && - test_cmp_rev HEAD^ copy && - test "$(cat new_file)" = dirty && - test "$(cat file)" = "modified again" -' +for i in true false + do + test_expect_success "pull --rebase --autostash & rebase.autostash=$i" ' + test_config rebase.autostash $i && + test_rebase_autostash + ' + done test_expect_success 'pull --rebase: --autostash & rebase.autostash unset' ' test_unconfig rebase.autostash && - git reset --hard before-rebase && - echo dirty >new_file && - git add new_file && - git pull --rebase --autostash . copy && - test_cmp_rev HEAD^ copy && - test "$(cat new_file)" = dirty && - test "$(cat file)" = "modified again" + test_rebase_autostash ' -test_expect_success 'pull --rebase --no-autostash & rebase.autostash=true' ' - test_config rebase.autostash true && - git reset --hard before-rebase && - echo dirty >new_file && - git add new_file && - test_must_fail git pull --rebase --no-autostash . copy 2>err && - test_i18ngrep "Cannot pull with rebase: Your index contains uncommitted changes." err -' - -test_expect_success 'pull --rebase --no-autostash & rebase.autostash=false' ' - test_config rebase.autostash false && - git reset --hard before-rebase && - echo dirty >new_file && - git add new_file && - test_must_fail git pull --rebase --no-autostash . copy 2>err && - test_i18ngrep "Cannot pull with rebase: Your index contains uncommitted changes." err -' +for i in true false + do + test_expect_success "pull --rebase --no-autostash & rebase.autostash=$i" ' + test_config rebase.autostash $i && + test_rebase_no_autostash + ' + done test_expect_success 'pull --rebase --no-autostash & rebase.autostash unset' ' test_unconfig rebase.autostash && - git reset --hard before-rebase && - echo dirty >new_file && - git add new_file && - test_must_fail git pull --rebase --no-autostash . copy 2>err && - test_i18ngrep "Cannot pull with rebase: Your index contains uncommitted changes." err + test_rebase_no_autostash ' -test_expect_success 'pull --autostash (without --rebase) should error out' ' - test_must_fail git pull --autostash . copy 2>err && - test_i18ngrep "only valid with --rebase" err -' - -test_expect_success 'pull --no-autostash (without --rebase) should error out' ' - test_must_fail git pull --no-autostash . copy 2>err && - test_i18ngrep "only valid with --rebase" err -' +for i in --autostash --no-autostash + do + test_expect_success "pull $i (without --rebase) is illegal" ' + test_must_fail git pull $i . copy 2>actual && + test_i18ngrep "only valid with --rebase" actual + ' + done test_expect_success 'pull.rebase' ' git reset --hard before-rebase && -- 2.7.1.340.g69eb491.dirty -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html