diff options
Diffstat (limited to 't/t6200-fmt-merge-msg.sh')
-rwxr-xr-x | t/t6200-fmt-merge-msg.sh | 530 |
1 files changed, 408 insertions, 122 deletions
diff --git a/t/t6200-fmt-merge-msg.sh b/t/t6200-fmt-merge-msg.sh index 42f6fff373..2e2fb0e957 100755 --- a/t/t6200-fmt-merge-msg.sh +++ b/t/t6200-fmt-merge-msg.sh @@ -7,73 +7,79 @@ test_description='fmt-merge-msg test' . ./test-lib.sh -datestamp=1151939923 -setdate () { - GIT_COMMITTER_DATE="$datestamp +0200" - GIT_AUTHOR_DATE="$datestamp +0200" - datestamp=`expr "$datestamp" + 1` - export GIT_COMMITTER_DATE GIT_AUTHOR_DATE -} - test_expect_success setup ' echo one >one && git add one && - setdate && + test_tick && git commit -m "Initial" && + git clone . remote && + echo uno >one && echo dos >two && git add two && - setdate && + test_tick && git commit -a -m "Second" && git checkout -b left && - echo $datestamp >one && - setdate && + echo "c1" >one && + test_tick && git commit -a -m "Common #1" && - echo $datestamp >one && - setdate && + echo "c2" >one && + test_tick && git commit -a -m "Common #2" && git branch right && - echo $datestamp >two && - setdate && - git commit -a -m "Left #3" && + echo "l3" >two && + test_tick && + GIT_COMMITTER_NAME="Another Committer" \ + GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #3" && - echo $datestamp >two && - setdate && - git commit -a -m "Left #4" && + echo "l4" >two && + test_tick && + GIT_COMMITTER_NAME="Another Committer" \ + GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #4" && - echo $datestamp >two && - setdate && - git commit -a -m "Left #5" && + echo "l5" >two && + test_tick && + GIT_COMMITTER_NAME="Another Committer" \ + GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #5" && + git tag tag-l5 && git checkout right && - echo $datestamp >three && + echo "r3" >three && git add three && - setdate && + test_tick && git commit -a -m "Right #3" && + git tag tag-r3 && - echo $datestamp >three && - setdate && + echo "r4" >three && + test_tick && git commit -a -m "Right #4" && - echo $datestamp >three && - setdate && + echo "r5" >three && + test_tick && git commit -a -m "Right #5" && - git show-branch -' + git checkout -b long && + i=0 && + while test $i -lt 30 + do + test_commit $i one && + i=$(($i+1)) + done && -cat >expected <<\EOF -Merge branch 'left' -EOF + git show-branch && -test_expect_success 'merge-msg test #1' ' + apos="'\''" +' + +test_expect_success 'message for merging local branch' ' + echo "Merge branch ${apos}left${apos}" >expected && git checkout master && git fetch . left && @@ -82,11 +88,8 @@ test_expect_success 'merge-msg test #1' ' test_cmp expected actual ' -cat >expected <<EOF -Merge branch 'left' of $(pwd) -EOF - -test_expect_success 'merge-msg test #2' ' +test_expect_success 'message for merging external branch' ' + echo "Merge branch ${apos}left${apos} of $(pwd)" >expected && git checkout master && git fetch "$(pwd)" left && @@ -95,149 +98,432 @@ test_expect_success 'merge-msg test #2' ' test_cmp expected actual ' -cat >expected <<\EOF -Merge branch 'left' +test_expect_success '[merge] summary/log configuration' ' + cat >expected <<-EOF && + Merge branch ${apos}left${apos} -* left: - Left #5 - Left #4 - Left #3 - Common #2 - Common #1 -EOF + # By Another Author (3) and A U Thor (2) + # Via Another Committer + * left: + Left #5 + Left #4 + Left #3 + Common #2 + Common #1 + EOF -test_expect_success 'merge-msg test #3-1' ' + test_config merge.log true && + test_unconfig merge.summary && - git config --unset-all merge.log - git config --unset-all merge.summary - git config merge.log true && + git checkout master && + test_tick && + git fetch . left && + + git fmt-merge-msg <.git/FETCH_HEAD >actual1 && + + test_unconfig merge.log && + test_config merge.summary true && git checkout master && - setdate && + test_tick && git fetch . left && - git fmt-merge-msg <.git/FETCH_HEAD >actual && + git fmt-merge-msg <.git/FETCH_HEAD >actual2 && + + test_cmp expected actual1 && + test_cmp expected actual2 +' + +test_expect_success 'setup FETCH_HEAD' ' + git checkout master && + test_tick && + git fetch . left +' + +test_expect_success 'merge.log=3 limits shortlog length' ' + cat >expected <<-EOF && + Merge branch ${apos}left${apos} + + # By Another Author (3) and A U Thor (2) + # Via Another Committer + * left: (5 commits) + Left #5 + Left #4 + Left #3 + ... + EOF + + git -c merge.log=3 fmt-merge-msg <.git/FETCH_HEAD >actual && test_cmp expected actual ' -test_expect_success 'merge-msg test #3-2' ' +test_expect_success 'merge.log=5 shows all 5 commits' ' + cat >expected <<-EOF && + Merge branch ${apos}left${apos} + + # By Another Author (3) and A U Thor (2) + # Via Another Committer + * left: + Left #5 + Left #4 + Left #3 + Common #2 + Common #1 + EOF + + git -c merge.log=5 fmt-merge-msg <.git/FETCH_HEAD >actual && + test_cmp expected actual +' - git config --unset-all merge.log - git config --unset-all merge.summary - git config merge.summary true && +test_expect_success '--log=5 with custom comment character' ' + cat >expected <<-EOF && + Merge branch ${apos}left${apos} + + x By Another Author (3) and A U Thor (2) + x Via Another Committer + * left: + Left #5 + Left #4 + Left #3 + Common #2 + Common #1 + EOF + + git -c core.commentchar="x" fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual && + test_cmp expected actual +' - git checkout master && - setdate && - git fetch . left && +test_expect_success 'merge.log=0 disables shortlog' ' + echo "Merge branch ${apos}left${apos}" >expected && + git -c merge.log=0 fmt-merge-msg <.git/FETCH_HEAD >actual && + test_cmp expected actual +' - git fmt-merge-msg <.git/FETCH_HEAD >actual && +test_expect_success '--log=3 limits shortlog length' ' + cat >expected <<-EOF && + Merge branch ${apos}left${apos} + + # By Another Author (3) and A U Thor (2) + # Via Another Committer + * left: (5 commits) + Left #5 + Left #4 + Left #3 + ... + EOF + + git fmt-merge-msg --log=3 <.git/FETCH_HEAD >actual && test_cmp expected actual ' -cat >expected <<\EOF -Merge branches 'left' and 'right' +test_expect_success '--log=5 shows all 5 commits' ' + cat >expected <<-EOF && + Merge branch ${apos}left${apos} + + # By Another Author (3) and A U Thor (2) + # Via Another Committer + * left: + Left #5 + Left #4 + Left #3 + Common #2 + Common #1 + EOF + + git fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual && + test_cmp expected actual +' -* left: - Left #5 - Left #4 - Left #3 - Common #2 - Common #1 +test_expect_success '--no-log disables shortlog' ' + echo "Merge branch ${apos}left${apos}" >expected && + git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual && + test_cmp expected actual +' -* right: - Right #5 - Right #4 - Right #3 - Common #2 - Common #1 -EOF +test_expect_success '--log=0 disables shortlog' ' + echo "Merge branch ${apos}left${apos}" >expected && + git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual && + test_cmp expected actual +' -test_expect_success 'merge-msg test #4-1' ' +test_expect_success 'fmt-merge-msg -m' ' + echo "Sync with left" >expected && + cat >expected.log <<-EOF && + Sync with left + + # By Another Author (3) and A U Thor (2) + # Via Another Committer + * ${apos}left${apos} of $(pwd): + Left #5 + Left #4 + Left #3 + Common #2 + Common #1 + EOF + + test_unconfig merge.log && + test_unconfig merge.summary && + git checkout master && + git fetch "$(pwd)" left && + git fmt-merge-msg -m "Sync with left" <.git/FETCH_HEAD >actual && + git fmt-merge-msg --log -m "Sync with left" \ + <.git/FETCH_HEAD >actual.log && + test_config merge.log true && + git fmt-merge-msg -m "Sync with left" \ + <.git/FETCH_HEAD >actual.log-config && + git fmt-merge-msg --no-log -m "Sync with left" \ + <.git/FETCH_HEAD >actual.nolog && + + test_cmp expected actual && + test_cmp expected.log actual.log && + test_cmp expected.log actual.log-config && + test_cmp expected actual.nolog +' - git config --unset-all merge.log - git config --unset-all merge.summary - git config merge.log true && +test_expect_success 'setup: expected shortlog for two branches' ' + cat >expected <<-EOF + Merge branches ${apos}left${apos} and ${apos}right${apos} + + # By Another Author (3) and A U Thor (2) + # Via Another Committer + * left: + Left #5 + Left #4 + Left #3 + Common #2 + Common #1 + + * right: + Right #5 + Right #4 + Right #3 + Common #2 + Common #1 + EOF +' +test_expect_success 'shortlog for two branches' ' + test_config merge.log true && + test_unconfig merge.summary && git checkout master && - setdate && + test_tick && git fetch . left right && + git fmt-merge-msg <.git/FETCH_HEAD >actual1 && - git fmt-merge-msg <.git/FETCH_HEAD >actual && + test_unconfig merge.log && + test_config merge.summary true && + git checkout master && + test_tick && + git fetch . left right && + git fmt-merge-msg <.git/FETCH_HEAD >actual2 && + + test_config merge.log yes && + test_unconfig merge.summary && + git checkout master && + test_tick && + git fetch . left right && + git fmt-merge-msg <.git/FETCH_HEAD >actual3 && + + test_unconfig merge.log && + test_config merge.summary yes && + git checkout master && + test_tick && + git fetch . left right && + git fmt-merge-msg <.git/FETCH_HEAD >actual4 && + + test_cmp expected actual1 && + test_cmp expected actual2 && + test_cmp expected actual3 && + test_cmp expected actual4 +' + +test_expect_success 'merge-msg -F' ' + test_unconfig merge.log && + test_config merge.summary yes && + git checkout master && + test_tick && + git fetch . left right && + git fmt-merge-msg -F .git/FETCH_HEAD >actual && test_cmp expected actual ' -test_expect_success 'merge-msg test #4-2' ' +test_expect_success 'merge-msg -F in subdirectory' ' + test_unconfig merge.log && + test_config merge.summary yes && + git checkout master && + test_tick && + git fetch . left right && + mkdir sub && + cp .git/FETCH_HEAD sub/FETCH_HEAD && + ( + cd sub && + git fmt-merge-msg -F FETCH_HEAD >../actual + ) && + test_cmp expected actual +' + +test_expect_success 'merge-msg with nothing to merge' ' + test_unconfig merge.log && + test_config merge.summary yes && + + >empty && + + ( + cd remote && + git checkout -b unrelated && + test_tick && + git fetch origin && + git fmt-merge-msg <.git/FETCH_HEAD >../actual + ) && + + test_cmp empty actual +' + +test_expect_success 'merge-msg tag' ' + cat >expected <<-EOF && + Merge tag ${apos}tag-r3${apos} - git config --unset-all merge.log - git config --unset-all merge.summary - git config merge.summary true && + * tag ${apos}tag-r3${apos}: + Right #3 + Common #2 + Common #1 + EOF + + test_unconfig merge.log && + test_config merge.summary yes && git checkout master && - setdate && - git fetch . left right && + test_tick && + git fetch . tag tag-r3 && git fmt-merge-msg <.git/FETCH_HEAD >actual && test_cmp expected actual ' -test_expect_success 'merge-msg test #5-1' ' +test_expect_success 'merge-msg two tags' ' + cat >expected <<-EOF && + Merge tags ${apos}tag-r3${apos} and ${apos}tag-l5${apos} + + * tag ${apos}tag-r3${apos}: + Right #3 + Common #2 + Common #1 + + # By Another Author (3) and A U Thor (2) + # Via Another Committer + * tag ${apos}tag-l5${apos}: + Left #5 + Left #4 + Left #3 + Common #2 + Common #1 + EOF - git config --unset-all merge.log - git config --unset-all merge.summary - git config merge.log yes && + test_unconfig merge.log && + test_config merge.summary yes && git checkout master && - setdate && - git fetch . left right && + test_tick && + git fetch . tag tag-r3 tag tag-l5 && git fmt-merge-msg <.git/FETCH_HEAD >actual && test_cmp expected actual ' -test_expect_success 'merge-msg test #5-2' ' +test_expect_success 'merge-msg tag and branch' ' + cat >expected <<-EOF && + Merge branch ${apos}left${apos}, tag ${apos}tag-r3${apos} + + * tag ${apos}tag-r3${apos}: + Right #3 + Common #2 + Common #1 + + # By Another Author (3) and A U Thor (2) + # Via Another Committer + * left: + Left #5 + Left #4 + Left #3 + Common #2 + Common #1 + EOF - git config --unset-all merge.log - git config --unset-all merge.summary - git config merge.summary yes && + test_unconfig merge.log && + test_config merge.summary yes && git checkout master && - setdate && - git fetch . left right && + test_tick && + git fetch . tag tag-r3 left && git fmt-merge-msg <.git/FETCH_HEAD >actual && test_cmp expected actual ' -test_expect_success 'merge-msg -F' ' +test_expect_success 'merge-msg lots of commits' ' + { + cat <<-EOF && + Merge branch ${apos}long${apos} + + * long: (35 commits) + EOF - git config --unset-all merge.log - git config --unset-all merge.summary - git config merge.summary yes && + i=29 && + while test $i -gt 9 + do + echo " $i" && + i=$(($i-1)) + done && + echo " ..." + } >expected && + + test_config merge.summary yes && git checkout master && - setdate && - git fetch . left right && + test_tick && + git fetch . long && - git fmt-merge-msg -F .git/FETCH_HEAD >actual && + git fmt-merge-msg <.git/FETCH_HEAD >actual && test_cmp expected actual ' -test_expect_success 'merge-msg -F in subdirectory' ' +test_expect_success 'merge-msg with "merging" an annotated tag' ' + test_config merge.log true && - git config --unset-all merge.log - git config --unset-all merge.summary - git config merge.summary yes && + git checkout master^0 && + git commit --allow-empty -m "One step ahead" && + git tag -a -m "An annotated one" annote HEAD && git checkout master && - setdate && - git fetch . left right && - mkdir sub && - cp .git/FETCH_HEAD sub/FETCH_HEAD && - ( - cd sub && - git fmt-merge-msg -F FETCH_HEAD >../actual - ) && - test_cmp expected actual + git fetch . annote && + + git fmt-merge-msg <.git/FETCH_HEAD >actual && + { + cat <<-\EOF + Merge tag '\''annote'\'' + + An annotated one + + * tag '\''annote'\'': + One step ahead + EOF + } >expected && + test_cmp expected actual && + + test_when_finished "git reset --hard" && + annote=$(git rev-parse annote) && + git merge --no-commit $annote && + { + cat <<-EOF + Merge tag '\''$annote'\'' + + An annotated one + + * tag '\''$annote'\'': + One step ahead + EOF + } >expected && + test_cmp expected .git/MERGE_MSG ' test_done |