@@ -247,3 +247,63 @@ def test_run_command_nonexistent_worktree(runner, initialized_repo):
247247 result = runner .invoke (cli , ["run" , "nonexistent" , "echo hello" ])
248248 assert result .exit_code == 4
249249 assert "not found" in result .output
250+
251+
252+ def test_sync_command_no_upstream (runner , initialized_repo , no_prompt ):
253+ """Test wt sync command when current worktree has no upstream."""
254+ result = runner .invoke (cli , ["sync" ])
255+ # Should show error about no upstream since initialized_repo doesn't have remote
256+ assert "no upstream" in result .output .lower () or "error" in result .output .lower ()
257+
258+
259+ def test_sync_command_all_worktrees (runner , initialized_repo , no_prompt ):
260+ """Test wt sync --all command."""
261+ # Create feature worktrees
262+ runner .invoke (cli , ["switch" , "-c" , "feat" ])
263+
264+ # Run sync on all worktrees - will have no upstream but shouldn't crash
265+ result = runner .invoke (cli , ["sync" , "--all" ])
266+ assert result .exit_code == 0 or result .exit_code == 3
267+ assert "Syncing" in result .output
268+
269+
270+ def test_sync_command_include (runner , initialized_repo , no_prompt ):
271+ """Test wt sync --include command."""
272+ # Create worktrees
273+ runner .invoke (cli , ["switch" , "-c" , "feat1" ])
274+ runner .invoke (cli , ["switch" , "-c" , "feat2" ])
275+
276+ # Sync only feat1
277+ result = runner .invoke (cli , ["sync" , "--include" , "feat1" ])
278+ assert result .exit_code == 0 or result .exit_code == 3
279+
280+
281+ def test_sync_command_exclude (runner , initialized_repo , no_prompt ):
282+ """Test wt sync --all --exclude command."""
283+ # Create worktrees
284+ runner .invoke (cli , ["switch" , "-c" , "feat1" ])
285+ runner .invoke (cli , ["switch" , "-c" , "feat2" ])
286+
287+ # Sync all except feat1
288+ result = runner .invoke (cli , ["sync" , "--all" , "--exclude" , "feat1" ])
289+ assert result .exit_code == 0 or result .exit_code == 3
290+
291+
292+ def test_sync_command_with_rebase (runner , initialized_repo , no_prompt ):
293+ """Test wt sync --rebase command."""
294+ # Run sync with rebase - will have no upstream but shouldn't crash
295+ result = runner .invoke (cli , ["sync" , "--rebase" ])
296+ assert result .exit_code == 0 or result .exit_code == 3
297+
298+
299+ def test_sync_command_invalid_args (runner , initialized_repo ):
300+ """Test wt sync with invalid argument combinations."""
301+ # Both include and exclude
302+ result = runner .invoke (cli , ["sync" , "--include" , "feat1" , "--exclude" , "feat2" ])
303+ assert result .exit_code == 2
304+ assert "Cannot use both" in result .output
305+
306+ # Exclude without all
307+ result = runner .invoke (cli , ["sync" , "--exclude" , "feat1" ])
308+ assert result .exit_code == 2
309+ assert "requires --all" in result .output
0 commit comments