@@ -108,13 +108,13 @@ func Test_diffWorktrees(t *testing.T) {
108108 Remote : "user@host.xz:path/to/repo1.git" ,
109109 Root : "/root" , Interval : 10 * time .Second , GitGC : "always" ,
110110 Worktrees : []mirror.WorktreeConfig {
111- {Link : "link" , Ref : "master" , Pathspec : "" },
112- {Link : "link2" , Ref : "other-branch" , Pathspec : "path" },
111+ {Link : "link" , Ref : "master" , Pathspecs : nil },
112+ {Link : "link2" , Ref : "other-branch" , Pathspecs : [] string { "path1" , "path2/**/*.yaml" , "*.c" } },
113113 },
114114 },
115115 wantNewWTCs : []mirror.WorktreeConfig {
116116 {Link : "link" , Ref : "master" },
117- {Link : "link2" , Ref : "other-branch" , Pathspec : "path" },
117+ {Link : "link2" , Ref : "other-branch" , Pathspecs : [] string { "path1" , "path2/**/*.yaml" , "*.c" } },
118118 },
119119 wantRemovedWTs : nil ,
120120 },
@@ -124,44 +124,68 @@ func Test_diffWorktrees(t *testing.T) {
124124 Remote : "user@host.xz:path/to/repo1.git" ,
125125 Root : "/root" , Interval : 10 * time .Second , GitGC : "always" ,
126126 Worktrees : []mirror.WorktreeConfig {
127- {Link : "link" , Ref : "master" , Pathspec : "" },
128- {Link : "link2" , Ref : "other-branch" , Pathspec : "path" },
127+ {Link : "link" , Ref : "master" , Pathspecs : nil },
128+ {Link : "link2" , Ref : "other-branch" , Pathspecs : []string {"path1" , "path2/**/*.yaml" , "*.c" }},
129+ {Link : "link3" , Ref : "other-branch" , Pathspecs : []string {"path" }},
129130 },
130131 },
131132 newRepoConf : & mirror.RepositoryConfig {
132133 Remote : "user@host.xz:path/to/repo1.git" ,
133134 Root : "/root" , Interval : 10 * time .Second , GitGC : "always" ,
134135 Worktrees : []mirror.WorktreeConfig {
135- {Link : "link" , Ref : "master" , Pathspec : "new-path" },
136- {Link : "link2" , Ref : "new-branch" , Pathspec : "path" },
136+ {Link : "link" , Ref : "master" , Pathspecs : []string {"new-path" }},
137+ {Link : "link2" , Ref : "new-branch" , Pathspecs : []string {"path1" , "path2/**/*.yaml" , "*.c" }},
138+ {Link : "link3" , Ref : "other-branch" , Pathspecs : []string {"path" , "new-path" }},
137139 },
138140 },
139141 wantNewWTCs : []mirror.WorktreeConfig {
140- {Link : "link" , Ref : "master" , Pathspec : "new-path" },
141- {Link : "link2" , Ref : "new-branch" , Pathspec : "path" },
142+ {Link : "link" , Ref : "master" , Pathspecs : []string {"new-path" }},
143+ {Link : "link2" , Ref : "new-branch" , Pathspecs : []string {"path1" , "path2/**/*.yaml" , "*.c" }},
144+ {Link : "link3" , Ref : "other-branch" , Pathspecs : []string {"path" , "new-path" }},
142145 },
143- wantRemovedWTs : []string {"link" , "link2" },
146+ wantRemovedWTs : []string {"link" , "link2" , "link3" },
147+ },
148+ {
149+ name : "rearrange-path" ,
150+ initialRepoConf : & mirror.RepositoryConfig {
151+ Remote : "user@host.xz:path/to/repo1.git" ,
152+ Root : "/root" , Interval : 10 * time .Second , GitGC : "always" ,
153+ Worktrees : []mirror.WorktreeConfig {
154+ {Link : "link" , Ref : "master" , Pathspecs : []string {"a" , "b/**/c" }},
155+ {Link : "link2" , Ref : "other-branch" , Pathspecs : []string {"path1" , "path2/**/*.yaml" , "*.c" }},
156+ },
157+ },
158+ newRepoConf : & mirror.RepositoryConfig {
159+ Remote : "user@host.xz:path/to/repo1.git" ,
160+ Root : "/root" , Interval : 10 * time .Second , GitGC : "always" ,
161+ Worktrees : []mirror.WorktreeConfig {
162+ {Link : "link" , Ref : "master" , Pathspecs : []string {"b/**/c" , "a" }},
163+ {Link : "link2" , Ref : "other-branch" , Pathspecs : []string {"path1" , "*.c" , "path2/**/*.yaml" }},
164+ },
165+ },
166+ wantNewWTCs : nil ,
167+ wantRemovedWTs : nil ,
144168 },
145169 {
146170 name : "add_new_link" ,
147171 initialRepoConf : & mirror.RepositoryConfig {
148172 Remote : "user@host.xz:path/to/repo1.git" ,
149173 Root : "/root" , Interval : 10 * time .Second , GitGC : "always" ,
150174 Worktrees : []mirror.WorktreeConfig {
151- {Link : "link" , Ref : "master" , Pathspec : "" },
152- {Link : "link2" , Ref : "other-branch" , Pathspec : "path" },
175+ {Link : "link" , Ref : "master" , Pathspecs : nil },
176+ {Link : "link2" , Ref : "other-branch" , Pathspecs : [] string { "path1" , "path2/**/*.yaml" , "*.c" } },
153177 },
154178 },
155179 newRepoConf : & mirror.RepositoryConfig {
156180 Remote : "user@host.xz:path/to/repo1.git" ,
157181 Root : "/root" , Interval : 10 * time .Second , GitGC : "always" ,
158182 Worktrees : []mirror.WorktreeConfig {
159- {Link : "link" , Ref : "master" , Pathspec : "" },
160- {Link : "link3" , Ref : "other-branch" , Pathspec : "path" },
183+ {Link : "link" , Ref : "master" , Pathspecs : nil },
184+ {Link : "link3" , Ref : "other-branch" , Pathspecs : [] string { "path1" , "path2/**/*.yaml" , "*.c" } },
161185 },
162186 },
163187 wantNewWTCs : []mirror.WorktreeConfig {
164- {Link : "link3" , Ref : "other-branch" , Pathspec : "path" },
188+ {Link : "link3" , Ref : "other-branch" , Pathspecs : [] string { "path1" , "path2/**/*.yaml" , "*.c" } },
165189 },
166190 wantRemovedWTs : []string {"link2" },
167191 },
0 commit comments