#!/bin/sh
test_description='test git rev-parse'
+ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
+ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+
. ./test-lib.sh
+test_one () {
+ dir="$1" &&
+ expect="$2" &&
+ shift &&
+ shift &&
+ echo "$expect" >expect &&
+ git -C "$dir" rev-parse "$@" >actual &&
+ test_cmp expect actual
+}
+
# usage: [options] label is-bare is-inside-git is-inside-work prefix git-dir absolute-git-dir
test_rev_parse () {
d=
check "@:normal" blob content
check "@:fun@ny" blob content
- git checkout -B newbranch master &&
+test_expect_success '@{1} works with only one reflog entry' '
- git checkout -B newbranch master &&
++ git checkout -B newbranch main &&
+ git reflog expire --expire=now refs/heads/newbranch &&
+ git commit --allow-empty -m "first after expiration" &&
+ test_cmp_rev newbranch~ newbranch@{1}
+'
+
+test_expect_success '@{0} works with empty reflog' '
++ git checkout -B newbranch main &&
+ git reflog expire --expire=now refs/heads/newbranch &&
+ test_cmp_rev newbranch newbranch@{0}
+'
+
test_done
ls patches/0001-Side-changes-1.patch patches/0002-Side-changes-2.patch patches/0003-Side-changes-3-with-n-backslash-n-in-it.patch
'
+test_expect_success 'filename length limit' '
+ test_when_finished "rm -f 000*" &&
+ rm -rf 000[1-9]-*.patch &&
+ for len in 15 25 35
+ do
+ git format-patch --filename-max-length=$len -3 side &&
+ max=$(
+ for patch in 000[1-9]-*.patch
+ do
+ echo "$patch" | wc -c
+ done |
+ sort -nr |
+ head -n 1
+ ) &&
+ test $max -le $len || return 1
+ done
+'
+
+test_expect_success 'filename length limit from config' '
+ test_when_finished "rm -f 000*" &&
+ rm -rf 000[1-9]-*.patch &&
+ for len in 15 25 35
+ do
+ git -c format.filenameMaxLength=$len format-patch -3 side &&
+ max=$(
+ for patch in 000[1-9]-*.patch
+ do
+ echo "$patch" | wc -c
+ done |
+ sort -nr |
+ head -n 1
+ ) &&
+ test $max -le $len || return 1
+ done
+'
+
+test_expect_success 'filename limit applies only to basename' '
+ test_when_finished "rm -rf patches/" &&
+ rm -rf patches/ &&
+ for len in 15 25 35
+ do
+ git format-patch -o patches --filename-max-length=$len -3 side &&
+ max=$(
+ for patch in patches/000[1-9]-*.patch
+ do
+ echo "${patch#patches/}" | wc -c
+ done |
+ sort -nr |
+ head -n 1
+ ) &&
+ test $max -le $len || return 1
+ done
+'
+
test_expect_success 'reroll count' '
rm -fr patches &&
- git format-patch -o patches --cover-letter --reroll-count 4 master..side >list &&
+ git format-patch -o patches --cover-letter --reroll-count 4 main..side >list &&
! grep -v "^patches/v4-000[0-3]-" list &&
sed -n -e "/^Subject: /p" $(cat list) >subjects &&
! grep -v "^Subject: \[PATCH v4 [0-3]/3\] " subjects
. ./test-lib.sh
- master_repo=master.git
+ main_repo=main.git
shared_repo=shared.git
+git_pack_redundant='git pack-redundant --i-still-use-this'
+
# Create commits in <repo> and assign each commit's oid to shell variables
# given in the arguments (A, B, and C). E.g.:
#
sort
}
- test_expect_success 'setup master repo' '
- git init --bare "$master_repo" &&
- create_commits_in "$master_repo" A B C D E F G H I J K L M N O P Q R
+ test_expect_success 'setup main repo' '
+ git init --bare "$main_repo" &&
+ create_commits_in "$main_repo" A B C D E F G H I J K L M N O P Q R
'
+test_expect_success 'master: pack-redundant works with no packfile' '
+ (
+ cd "$master_repo" &&
+ cat >expect <<-EOF &&
+ fatal: Zero packs found!
+ EOF
+ test_must_fail $git_pack_redundant --all >actual 2>&1 &&
+ test_cmp expect actual
+ )
+'
+
#############################################################################
# Chart of packs and objects for this test case
#
# | T A B C D E F G H I J K L M N O P Q R
# ----+--------------------------------------
# P1 | x x x x x x x x
-# P2 | x x x x x x x
-# P3 | x x x x x x
# ----+--------------------------------------
-# ALL | x x x x x x x x x x x x x x x
+# ALL | x x x x x x x x
#
#############################################################################
- test_expect_success 'master: pack-redundant works with one packfile' '
- create_pack_in "$master_repo" P1 <<-EOF &&
-test_expect_success 'main: no redundant for pack 1, 2, 3' '
++test_expect_success 'main: pack-redundant works with one packfile' '
+ create_pack_in "$main_repo" P1 <<-EOF &&
$T
$A
$B
$F
$R
EOF
- cd "$master_repo" &&
+ (
- test_expect_success 'master: no redundant for pack 1, 2, 3' '
- create_pack_in "$master_repo" P2 <<-EOF &&
++ cd "$main_repo" &&
+ $git_pack_redundant --all >out &&
+ test_must_be_empty out
+ )
+'
+
+#############################################################################
+# Chart of packs and objects for this test case
+#
+# | T A B C D E F G H I J K L M N O P Q R
+# ----+--------------------------------------
+# P1 | x x x x x x x x
+# P2 | x x x x x x x
+# P3 | x x x x x x
+# ----+--------------------------------------
+# ALL | x x x x x x x x x x x x x x x
+#
+#############################################################################
++test_expect_success 'main: no redundant for pack 1, 2, 3' '
+ create_pack_in "$main_repo" P2 <<-EOF &&
$B
$C
$D
$M
EOF
(
- cd "$master_repo" &&
+ cd "$main_repo" &&
- git pack-redundant --all >out &&
+ $git_pack_redundant --all >out &&
test_must_be_empty out
)
'
)
'
- test_expect_success 'master: remove redundant packs and pass fsck' '
+ test_expect_success 'main: remove redundant packs and pass fsck' '
(
- cd "$master_repo" &&
+ cd "$main_repo" &&
- git pack-redundant --all | xargs rm &&
+ $git_pack_redundant --all | xargs rm &&
git fsck &&
- git pack-redundant --all >out &&
+ $git_pack_redundant --all >out &&
test_must_be_empty out
)
'
'
-test_expect_success 'push with HEAD' '
-
- mk_test testrepo heads/main &&
- git checkout main &&
- git push testrepo HEAD &&
- check_push_result testrepo $the_commit heads/main
-
-'
-
-test_expect_success 'push with HEAD nonexisting at remote' '
-
- mk_test testrepo heads/main &&
- git checkout -b local main &&
- git push testrepo HEAD &&
- check_push_result testrepo $the_commit heads/local
-'
-
-test_expect_success 'push with +HEAD' '
+for head in HEAD @
+do
- mk_test testrepo heads/main &&
- git checkout main &&
- git branch -D local &&
- git checkout -b local &&
- git push testrepo main local &&
- check_push_result testrepo $the_commit heads/main &&
- check_push_result testrepo $the_commit heads/local &&
+ test_expect_success "push with $head" '
-
- mk_test testrepo heads/master &&
- git checkout master &&
++ mk_test testrepo heads/main &&
++ git checkout main &&
+ git push testrepo $head &&
- check_push_result testrepo $the_commit heads/master
-
++ check_push_result testrepo $the_commit heads/main
+ '
- # Without force rewinding should fail
- git reset --hard HEAD^ &&
- test_must_fail git push testrepo HEAD &&
- check_push_result testrepo $the_commit heads/local &&
+ test_expect_success "push with $head nonexisting at remote" '
-
- mk_test testrepo heads/master &&
- git checkout -b local master &&
- test_when_finished "git checkout master; git branch -D local" &&
++ mk_test testrepo heads/main &&
++ git checkout -b local main &&
++ test_when_finished "git checkout main; git branch -D local" &&
+ git push testrepo $head &&
+ check_push_result testrepo $the_commit heads/local
+ '
- # With force rewinding should succeed
- git push testrepo +HEAD &&
- check_push_result testrepo $the_first_commit heads/local
+ test_expect_success "push with +$head" '
-
- mk_test testrepo heads/master &&
- git checkout -b local master &&
- test_when_finished "git checkout master; git branch -D local" &&
- git push testrepo master local &&
- check_push_result testrepo $the_commit heads/master &&
++ mk_test testrepo heads/main &&
++ git checkout -b local main &&
++ test_when_finished "git checkout main; git branch -D local" &&
++ git push testrepo main local &&
++ check_push_result testrepo $the_commit heads/main &&
+ check_push_result testrepo $the_commit heads/local &&
-'
+ # Without force rewinding should fail
+ git reset --hard $head^ &&
+ test_must_fail git push testrepo $head &&
+ check_push_result testrepo $the_commit heads/local &&
-test_expect_success 'push HEAD with non-existent, incomplete dest' '
+ # With force rewinding should succeed
+ git push testrepo +$head &&
+ check_push_result testrepo $the_first_commit heads/local
-
+ '
- mk_test testrepo &&
- git checkout main &&
- git push testrepo HEAD:branch &&
- check_push_result testrepo $the_commit heads/branch
+ test_expect_success "push $head with non-existent, incomplete dest" '
-
+ mk_test testrepo &&
- git checkout master &&
++ git checkout main &&
+ git push testrepo $head:branch &&
+ check_push_result testrepo $the_commit heads/branch
-'
+ '
-test_expect_success 'push with config remote.*.push = HEAD' '
+ test_expect_success "push with config remote.*.push = $head" '
-
+ mk_test testrepo heads/local &&
- git checkout master &&
++ git checkout main &&
+ git branch -f local $the_commit &&
+ test_when_finished "git branch -D local" &&
+ (
+ cd testrepo &&
+ git checkout local &&
+ git reset --hard $the_first_commit
+ ) &&
+ test_config remote.there.url testrepo &&
+ test_config remote.there.push $head &&
- test_config branch.master.remote there &&
++ test_config branch.main.remote there &&
+ git push &&
- check_push_result testrepo $the_commit heads/master &&
++ check_push_result testrepo $the_commit heads/main &&
+ check_push_result testrepo $the_first_commit heads/local
+ '
- mk_test testrepo heads/local &&
- git checkout main &&
- git branch -f local $the_commit &&
- (
- cd testrepo &&
- git checkout local &&
- git reset --hard $the_first_commit
- ) &&
- test_config remote.there.url testrepo &&
- test_config remote.there.push HEAD &&
- test_config branch.main.remote there &&
- git push &&
- check_push_result testrepo $the_commit heads/main &&
- check_push_result testrepo $the_first_commit heads/local
-'
+done
test_expect_success 'push with remote.pushdefault' '
- mk_test up_repo heads/master &&
- mk_test down_repo heads/master &&
+ mk_test up_repo heads/main &&
+ mk_test down_repo heads/main &&
test_config remote.up.url up_repo &&
test_config remote.down.url down_repo &&
- test_config branch.master.remote up &&
+ test_config branch.main.remote up &&
test_config remote.pushdefault down &&
test_config push.default matching &&
git push &&
test_i18ngrep "locally recorded submodule modifications" err
'
- git -C superclone pull --rebase --recurse-submodules origin master
+test_expect_success 'pull --rebase --recurse-submodules (no submodule changes, no fork-point)' '
+ # This tests the following scenario :
+ # - local submodule does not have new commits
+ # - local superproject has new commits that *do not* change the submodule pointer
+ # - upstream superproject has new commits that *do not* change the submodule pointer
+ # - local superproject branch has no fork-point with its remote-tracking counter-part
+
+ # create upstream superproject
+ test_create_repo submodule &&
+ test_commit -C submodule first_in_sub &&
+
+ test_create_repo superprojet &&
+ test_commit -C superprojet first_in_super &&
+ git -C superprojet submodule add ../submodule &&
+ git -C superprojet commit -m "add submodule" &&
+ test_commit -C superprojet third_in_super &&
+
+ # clone superproject
+ git clone --recurse-submodules superprojet superclone &&
+
+ # add commits upstream
+ test_commit -C superprojet fourth_in_super &&
+
+ # create topic branch in clone, not based on any remote-tracking branch
+ git -C superclone checkout -b feat HEAD~1 &&
+ test_commit -C superclone first_on_feat &&
++ git -C superclone pull --rebase --recurse-submodules origin HEAD
+'
+
+# NOTE:
+#
+# This test is particular because there is only a single commit in the upstream superproject
+# 'parent' (which adds the submodule 'a-submodule'). The clone of the superproject
+# ('child') hard-resets its branch to a new root commit with the same tree as the one
+# from the upstream superproject, so that its branch has no merge-base with its
+# remote-tracking counterpart, and then calls 'git pull --recurse-submodules --rebase'.
+# The result is that the local branch is reset to the remote-tracking branch (as it was
+# originally before the hard-reset).
+
+# The only commit in the range generated by 'submodule.c::submodule_touches_in_range' and
+# passed to 'submodule.c::collect_changed_submodules' is the new (regenerated) initial commit,
+# which adds the submodule.
+# However, 'submodule_touches_in_range' does not error (even though this commit adds the submodule)
+# because 'combine-diff.c::diff_tree_combined' returns early, as the initial commit has no parents.
test_expect_success 'branch has no merge base with remote-tracking counterpart' '
rm -rf parent child &&
git clone parent child &&
- # Reset master so that it has no merge base with
- # refs/remotes/origin/master.
- # Reset main so that it has no merge base with
- # refs/remotes/origin/main.
++ # Reset the current branch so that it has no merge base with
++ # the remote-tracking branch.
OTHER=$(git -C child commit-tree -m bar \
$(git -C child rev-parse HEAD^{tree})) &&
git -C child reset --hard "$OTHER" &&
test_description='--graph and simplified history'
+ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
+ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+
. ./test-lib.sh
+. "$TEST_DIRECTORY"/lib-log-graph.sh
+
+check_graph () {
+ cat >expect &&
+ lib_test_cmp_graph --format=%s "$@"
+}
test_expect_success 'set up rev-list --graph test' '
# 3 commits on branch A