MCPcopy Create free account
hub / github.com/cli/cli / TestParseWorktrees

Function TestParseWorktrees

git/client_test.go:1887–1984  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1885}
1886
1887func TestParseWorktrees(t *testing.T) {
1888 tests := []struct {
1889 name string
1890 out string
1891 want []Worktree
1892 }{
1893 {
1894 name: "empty output",
1895 out: "",
1896 want: nil,
1897 },
1898 {
1899 name: "single worktree",
1900 out: heredoc.Doc(`
1901 worktree /path/to/main
1902 HEAD abc123
1903 branch refs/heads/main
1904 `),
1905 want: []Worktree{
1906 {Path: "/path/to/main", Ref: "refs/heads/main"},
1907 },
1908 },
1909 {
1910 name: "multiple worktrees",
1911 out: heredoc.Doc(`
1912 worktree /path/to/main
1913 HEAD abc123
1914 branch refs/heads/main
1915
1916 worktree /path/to/feature-wt
1917 HEAD def456
1918 branch refs/heads/feature
1919 `),
1920 want: []Worktree{
1921 {Path: "/path/to/main", Ref: "refs/heads/main"},
1922 {Path: "/path/to/feature-wt", Ref: "refs/heads/feature"},
1923 },
1924 },
1925 {
1926 name: "detached HEAD has no branch",
1927 out: heredoc.Doc(`
1928 worktree /path/to/main
1929 HEAD abc123
1930 branch refs/heads/main
1931
1932 worktree /path/to/detached
1933 HEAD def456
1934 detached
1935 `),
1936 want: []Worktree{
1937 {Path: "/path/to/main", Ref: "refs/heads/main"},
1938 {Path: "/path/to/detached", Ref: ""},
1939 },
1940 },
1941 {
1942 name: "no trailing blank line",
1943 out: "worktree /path/to/main\nHEAD abc123\nbranch refs/heads/main",
1944 want: []Worktree{

Callers

nothing calls this directly

Calls 3

parseWorktreesFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected