24
)
25
}
26
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="file://$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
+
49
tokens_match () {
50
echo "$1" | tr ' ' '\012' | sort | sed -e '/^$/d' >expect &&
51
echo "$2" | tr ' ' '\012' | sort | sed -e '/^$/d' >actual &&
1040
)
1041
'
1042
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 matching 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 'configured pushurl makes URL-valued pushRemote trackable' '
1075
+ setup_url_pushremote &&
1076
+
1077
+ (
1078
+ cd client &&
1079
+ git remote rename origin upstream &&
1080
+ git remote add -f origin ../fork.git &&
1081
+ git remote set-url --push origin "$fork_url"
1082
+ ) &&
1083
+
1084
+ check_status <<-EOF
1085
+ On branch topic
1086
+ Your branch is ahead of ${SQ}upstream/main${SQ} by 1 commit.
1087
+
1088
+ Your branch is up to date with ${SQ}origin/topic${SQ}.
1089
+
1090
+ nothing to commit, working tree clean
1091
+ EOF
1092
+'
1093
+
1094
+test_expect_success 'pushInsteadOf URL pushRemote is trackable' '
1095
+ setup_url_pushremote &&
1096
+ (
1097
+ cd client &&
1098
+ git remote rename origin upstream &&
1099
+ git remote add -f origin "$fork_url" &&
1100
+ git config "url.$fork_url.pushInsteadOf" fork: &&
1101
+ git config branch.topic.pushRemote fork:
1102
+ ) &&
1103
+
1104
+ check_status <<-EOF
1105
+ On branch topic
1106
+ Your branch is ahead of ${SQ}upstream/main${SQ} by 1 commit.
1107
+
1108
+ Your branch is up to date with ${SQ}origin/topic${SQ}.
1109
+
1110
+ nothing to commit, working tree clean
1111
+ EOF
1112
+'
1113
+
1114
+test_expect_success 'up-to-date URL push refreshes stale tracking branch' '
1115
+ setup_url_pushremote &&
1116
+ (
1117
+ cd client &&
1118
+ git remote rename origin upstream &&
1119
+ git remote add -f origin "$fork_url" &&
1120
+ git commit --allow-empty -m another-topic-change &&
1121
+ git -C ../fork.git fetch ../client topic:topic
1122
+ ) &&
1123
+
1124
+ check_status <<-EOF &&
1125
+ On branch topic
1126
+ Your branch is ahead of ${SQ}upstream/main${SQ} by 2 commits.
1127
+
1128
+ Your branch is ahead of ${SQ}origin/topic${SQ} by 1 commit.
1129
+ (use "git push" to publish your local commits)
1130
+
1131
+ nothing to commit, working tree clean
1132
+ EOF
1133
+
1134
+ git -C client push >actual 2>&1 &&
1135
+ test_grep "Everything up-to-date" actual &&
1136
+
1137
+ check_status <<-EOF
1138
+ On branch topic
1139
+ Your branch is ahead of ${SQ}upstream/main${SQ} by 2 commits.
1140
+
1141
+ Your branch is up to date with ${SQ}origin/topic${SQ}.
1142
+
1143
+ nothing to commit, working tree clean
1144
+ EOF
1145
+'
1146
+
1147
+test_expect_success 'duplicate remote URL leaves URL-valued pushRemote ambiguous' '
1148
+ setup_url_pushremote &&
1149
+ (
1150
+ cd client &&
1151
+ git remote rename origin upstream &&
1152
+ git remote add -f origin "$fork_url" &&
1153
+ git remote add duplicate "$fork_url"
1154
+ ) &&
1155
+
1156
+ check_status <<-EOF
1157
+ On branch topic
1158
+ Your branch is ahead of ${SQ}upstream/main${SQ} by 1 commit.
1159
+ (use "git push" to publish your local commits)
1160
+
1161
+ nothing to commit, working tree clean
1162
+ EOF
1163
+'
1164
+
1165
test_expect_success 'rename handles remote without fetch refspec' '
1166
git clone --bare one no-refspec.git &&
1167
# confirm assumption that bare clone does not create refspec