1717
test_cmp expect actual
1718
'
1719
1720
+test_expect_success '--forked: setup' '
1721
+ test_create_repo forked-upstream &&
1722
+ (
1723
+ cd forked-upstream &&
1724
+ test_commit base &&
1725
+ git branch one base &&
1726
+ git branch two base
1727
+ ) &&
1728
+
1729
+ test_create_repo forked-other &&
1730
+ (
1731
+ cd forked-other &&
1732
+ test_commit other-base &&
1733
+ git branch foreign other-base
1734
+ ) &&
1735
+
1736
+ git clone forked-upstream forked &&
1737
+ (
1738
+ cd forked &&
1739
+ git remote add -f other ../forked-other &&
1740
+ git branch local-base &&
1741
+ git branch --track local-one origin/one &&
1742
+ git branch --track local-two origin/two &&
1743
+ git branch --track local-foreign other/foreign &&
1744
+ git branch --track local-onbase local-base &&
1745
+
1746
+ git checkout local-one &&
1747
+ test_commit --no-tag local-one-work local-one.t &&
1748
+ git checkout local-foreign &&
1749
+ test_commit --no-tag local-foreign-work local-foreign.t
1750
+ )
1751
+'
1752
+
1753
+test_expect_success '--forked <upstream-tracking-branch> filters by upstream' '
1754
+ git -C forked branch --forked origin/one --format="%(refname:short)" >actual &&
1755
+ echo local-one >expect &&
1756
+ test_cmp expect actual
1757
+'
1758
+
1759
+test_expect_success '--forked <glob> filters by wildmatch' '
1760
+ git -C forked branch --forked "origin/*" --format="%(refname:short)" >actual &&
1761
+ cat >expect <<-\EOF &&
1762
+ local-one
1763
+ local-two
1764
+ main
1765
+ EOF
1766
+ test_cmp expect actual
1767
+'
1768
+
1769
+test_expect_success '--forked <local-branch> matches branches with local upstream' '
1770
+ git -C forked branch --forked local-base --format="%(refname:short)" >actual &&
1771
+ echo local-onbase >expect &&
1772
+ test_cmp expect actual
1773
+'
1774
+
1775
+test_expect_success '--forked can be repeated to widen the filter' '
1776
+ git -C forked branch --forked origin/one --forked other/foreign --format="%(refname:short)" >actual &&
1777
+ cat >expect <<-\EOF &&
1778
+ local-foreign
1779
+ local-one
1780
+ EOF
1781
+ test_cmp expect actual
1782
+'
1783
+
1784
+test_expect_success '--forked combines literal and glob arguments' '
1785
+ git -C forked branch --forked local-base --forked "other/*" --format="%(refname:short)" >actual &&
1786
+ cat >expect <<-\EOF &&
1787
+ local-foreign
1788
+ local-onbase
1789
+ EOF
1790
+ test_cmp expect actual
1791
+'
1792
+
1793
+test_expect_success '--forked "*/*" covers every remote-tracking upstream' '
1794
+ git -C forked branch --forked "*/*" --format="%(refname:short)" >actual &&
1795
+ cat >expect <<-\EOF &&
1796
+ local-foreign
1797
+ local-one
1798
+ local-two
1799
+ main
1800
+ EOF
1801
+ test_cmp expect actual
1802
+'
1803
+
1804
+test_expect_success '--forked composes with --no-merged' '
1805
+ git -C forked branch --forked "origin/*" --no-merged origin/one \
1806
+ --format="%(refname:short)" >actual &&
1807
+ echo local-one >expect &&
1808
+ test_cmp expect actual
1809
+'
1810
+
1811
+test_expect_success '--forked <remote> uses the branch <remote>/HEAD points at' '
1812
+ git -C forked branch --forked origin --format="%(refname:short)" >actual &&
1813
+ echo main >expect &&
1814
+ test_cmp expect actual
1815
+'
1816
+
1817
+test_expect_success '--forked narrows a <pattern> argument' '
1818
+ git -C forked branch --forked "origin/*" "local-*" \
1819
+ --format="%(refname:short)" >actual &&
1820
+ cat >expect <<-\EOF &&
1821
+ local-one
1822
+ local-two
1823
+ EOF
1824
+ test_cmp expect actual
1825
+'
1826
+
1827
+test_expect_success '--forked rejects unknown branch/pattern' '
1828
+ test_must_fail git -C forked branch --forked nope 2>err &&
1829
+ test_grep "not a valid branch or pattern" err
1830
+'
1831
+
1832
+test_expect_success '--forked requires a value' '
1833
+ test_must_fail git -C forked branch --forked 2>err &&
1834
+ test_grep "requires a value" err
1835
+'
1836
+
1837
test_done