@@ -24,6 +24,28 @@ setup_repository () {
2424 )
2525}
2626
27+ setup_url_pushremote () {
28+ rm -rf fork.git client &&
29+ git clone --bare one fork.git &&
30+ git clone one client &&
31+ fork_url=" $TRASH_DIRECTORY /fork.git" &&
32+ (
33+ cd client &&
34+ git checkout -b topic --track origin/main &&
35+ git commit --allow-empty -m topic-change &&
36+ git config push.default current &&
37+ git config status.compareBranches " @{upstream} @{push}" &&
38+ git config branch.topic.pushRemote " $fork_url " &&
39+ git push
40+ )
41+ }
42+
43+ check_status () {
44+ git -C client status > actual &&
45+ cat > expected &&
46+ test_cmp expected actual
47+ }
48+
2749tokens_match () {
2850 echo " $1 " | tr ' ' ' \012' | sort | sed -e ' /^$/d' > expect &&
2951 echo " $2 " | tr ' ' ' \012' | sort | sed -e ' /^$/d' > actual &&
@@ -1018,6 +1040,88 @@ test_expect_success 'rename a remote renames repo remote.pushDefault but keeps g
10181040 )
10191041'
10201042
1043+ test_expect_success ' URL-valued pushRemote without matching remote is not trackable' '
1044+ setup_url_pushremote &&
1045+
1046+ check_status <<-EOF
1047+ On branch topic
1048+ Your branch is ahead of ${SQ}origin/main${SQ} by 1 commit.
1049+ (use "git push" to publish your local commits)
1050+
1051+ nothing to commit, working tree clean
1052+ EOF
1053+ '
1054+
1055+ test_expect_success ' adding fork remote makes URL-valued pushRemote trackable' '
1056+ setup_url_pushremote &&
1057+
1058+ (
1059+ cd client &&
1060+ git remote rename origin upstream &&
1061+ git remote add -f origin "$fork_url"
1062+ ) &&
1063+
1064+ check_status <<-EOF
1065+ On branch topic
1066+ Your branch is ahead of ${SQ}upstream/main${SQ} by 1 commit.
1067+
1068+ Your branch is up to date with ${SQ}origin/topic${SQ}.
1069+
1070+ nothing to commit, working tree clean
1071+ EOF
1072+ '
1073+
1074+ test_expect_success ' up-to-date URL push refreshes stale tracking branch' '
1075+ setup_url_pushremote &&
1076+ (
1077+ cd client &&
1078+ git remote rename origin upstream &&
1079+ git remote add -f origin "$fork_url" &&
1080+ git commit --allow-empty -m another-topic-change &&
1081+ git -C ../fork.git fetch ../client topic:topic
1082+ ) &&
1083+
1084+ check_status <<-EOF &&
1085+ On branch topic
1086+ Your branch is ahead of ${SQ}upstream/main${SQ} by 2 commits.
1087+
1088+ Your branch is ahead of ${SQ}origin/topic${SQ} by 1 commit.
1089+ (use "git push" to publish your local commits)
1090+
1091+ nothing to commit, working tree clean
1092+ EOF
1093+
1094+ git -C client push >actual 2>&1 &&
1095+ test_grep "Everything up-to-date" actual &&
1096+
1097+ check_status <<-EOF
1098+ On branch topic
1099+ Your branch is ahead of ${SQ}upstream/main${SQ} by 2 commits.
1100+
1101+ Your branch is up to date with ${SQ}origin/topic${SQ}.
1102+
1103+ nothing to commit, working tree clean
1104+ EOF
1105+ '
1106+
1107+ test_expect_success ' duplicate remote URL leaves URL-valued pushRemote ambiguous' '
1108+ setup_url_pushremote &&
1109+ (
1110+ cd client &&
1111+ git remote rename origin upstream &&
1112+ git remote add -f origin "$fork_url" &&
1113+ git remote add duplicate "$fork_url"
1114+ ) &&
1115+
1116+ check_status <<-EOF
1117+ On branch topic
1118+ Your branch is ahead of ${SQ}upstream/main${SQ} by 1 commit.
1119+ (use "git push" to publish your local commits)
1120+
1121+ nothing to commit, working tree clean
1122+ EOF
1123+ '
1124+
10211125test_expect_success ' rename handles remote without fetch refspec' '
10221126 git clone --bare one no-refspec.git &&
10231127 # confirm assumption that bare clone does not create refspec
0 commit comments