Commit c4cdcb68ce13515b0852719b9690a470731c3d5d

Stefan Sperling 2019-04-03T16:17:53

add support for partial updates, which affect specific paths only

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
diff --git a/got/got.1 b/got/got.1
index 785da13..83aee65 100644
--- a/got/got.1
+++ b/got/got.1
@@ -86,7 +86,7 @@ Only files beneath the specified
 .Ar path-prefix
 will be checked out.
 .El
-.It Cm update [ Fl c Ar commit ] [ work-tree-path ]
+.It Cm update [ Fl c Ar commit ] [ Ar path ]
 Update an existing work tree to another commit on the current branch.
 By default, the latest commit on the current branch is assumed.
 Show the status of each affected file, using the following status codes:
@@ -100,10 +100,14 @@ Show the status of each affected file, using the following status codes:
 .It ! Ta a missing versioned file was restored
 .El
 .Pp
-If the
-.Ar work tree path
-is omitted, use the current working directory.
-.Pp
+If a
+.Ar path
+is specified, restrict the update operation to files at or within this path.
+Files outside this path will remain at their currently recorded base commit.
+Some operations may refuse to run while the work tree contains files from
+multiple base commits.
+Inconsistent base commits in a work tree can be repaired by running another
+update operation across the entire work tree.
 .Pp
 The options for
 .Cm got update
diff --git a/got/got.c b/got/got.c
index cef2aab..3ae9806 100644
--- a/got/got.c
+++ b/got/got.c
@@ -423,7 +423,7 @@ cmd_checkout(int argc, char *argv[])
 			goto done;
 	}
 
-	error = got_worktree_checkout_files(worktree, repo,
+	error = got_worktree_checkout_files(worktree, "", repo,
 	    checkout_progress, worktree_path, check_cancelled, NULL);
 	if (error != NULL)
 		goto done;
@@ -440,7 +440,7 @@ done:
 __dead static void
 usage_update(void)
 {
-	fprintf(stderr, "usage: %s update [-c commit] [worktree-path]\n",
+	fprintf(stderr, "usage: %s update [-c commit] [path]\n",
 	    getprogname());
 	exit(1);
 }
@@ -465,7 +465,7 @@ cmd_update(int argc, char *argv[])
 	const struct got_error *error = NULL;
 	struct got_repository *repo = NULL;
 	struct got_worktree *worktree = NULL;
-	char *worktree_path = NULL;
+	char *worktree_path = NULL, *path = NULL;
 	struct got_object_id *commit_id = NULL;
 	char *commit_id_str = NULL;
 	int ch, did_something = 0;
@@ -491,25 +491,28 @@ cmd_update(int argc, char *argv[])
 	    "unveil", NULL) == -1)
 		err(1, "pledge");
 #endif
+	worktree_path = getcwd(NULL, 0);
+	if (worktree_path == NULL) {
+		error = got_error_from_errno();
+		goto done;
+	}
+	error = got_worktree_open(&worktree, worktree_path);
+	if (error)
+		goto done;
+
 	if (argc == 0) {
-		worktree_path = getcwd(NULL, 0);
-		if (worktree_path == NULL) {
+		path = strdup("");
+		if (path == NULL) {
 			error = got_error_from_errno();
 			goto done;
 		}
 	} else if (argc == 1) {
-		worktree_path = realpath(argv[0], NULL);
-		if (worktree_path == NULL) {
-			error = got_error_from_errno();
+		error = got_worktree_resolve_path(&path, worktree, argv[0]);
+		if (error)
 			goto done;
-		}
 	} else
 		usage_update();
 
-	error = got_worktree_open(&worktree, worktree_path);
-	if (error != NULL)
-		goto done;
-
 	error = got_repo_open(&repo, got_worktree_get_repo_path(worktree));
 	if (error != NULL)
 		goto done;
@@ -549,7 +552,7 @@ cmd_update(int argc, char *argv[])
 			goto done;
 	}
 
-	error = got_worktree_checkout_files(worktree, repo,
+	error = got_worktree_checkout_files(worktree, path, repo,
 	    update_progress, &did_something, check_cancelled, NULL);
 	if (error != NULL)
 		goto done;
@@ -560,6 +563,7 @@ cmd_update(int argc, char *argv[])
 		printf("Already up-to-date\n");
 done:
 	free(worktree_path);
+	free(path);
 	free(commit_id);
 	free(commit_id_str);
 	return error;
diff --git a/include/got_worktree.h b/include/got_worktree.h
index d49c5f8..b3cc035 100644
--- a/include/got_worktree.h
+++ b/include/got_worktree.h
@@ -108,9 +108,21 @@ typedef const struct got_error *(*got_worktree_cancel_cb)(void *);
  * inside the tree corresponding to the work tree's base commit.
  * The checkout progress callback will be invoked with the provided
  * void * argument, and the path of each checked out file.
+ *
+ * It is possible to restrict the checkout operation to a specific path in
+ * the work tree, in which case all files outside this path will remain at
+ * their currently recorded base commit. Inconsistent base commits can be
+ * repaired later by running another update operation across the entire work
+ * tree. Inconsistent base-commits may also occur if this function runs into
+ * an error or if the checkout operation is cancelled by the cancel callback.
+ * The specified path is relative to the work tree's root. Pass "" to check
+ * out files across the entire work tree.
+ *
+ * Some operations may refuse to run while the work tree contains files from
+ * multiple base commits.
  */
 const struct got_error *got_worktree_checkout_files(struct got_worktree *,
-    struct got_repository *, got_worktree_checkout_cb, void *,
+    const char *, struct got_repository *, got_worktree_checkout_cb, void *,
     got_worktree_cancel_cb, void *);
 
 /* A callback function which is invoked to report a path's status. */
diff --git a/lib/fileindex.c b/lib/fileindex.c
index 4a33abd..544113f 100644
--- a/lib/fileindex.c
+++ b/lib/fileindex.c
@@ -618,13 +618,13 @@ walk_fileindex(struct got_fileindex *fileindex, struct got_fileindex_entry *ie)
 
 static const struct got_error *
 diff_fileindex_tree(struct got_fileindex *, struct got_fileindex_entry **,
-    struct got_tree_object *, const char *, struct got_repository *,
-    struct got_fileindex_diff_tree_cb *, void *);
+    struct got_tree_object *, const char *, const char *,
+    struct got_repository *, struct got_fileindex_diff_tree_cb *, void *);
 
 static const struct got_error *
 walk_tree(struct got_tree_entry **next, struct got_fileindex *fileindex,
     struct got_fileindex_entry **ie, struct got_tree_entry *te,
-    const char *path, struct got_repository *repo,
+    const char *path, const char *entry_name, struct got_repository *repo,
     struct got_fileindex_diff_tree_cb *cb, void *cb_arg)
 {
 	const struct got_error *err = NULL;
@@ -644,7 +644,7 @@ walk_tree(struct got_tree_entry **next, struct got_fileindex *fileindex,
 		}
 
 		err = diff_fileindex_tree(fileindex, ie, subtree,
-		    subpath, repo, cb, cb_arg);
+		    subpath, entry_name, repo, cb, cb_arg);
 		free(subpath);
 		got_object_tree_close(subtree);
 		if (err)
@@ -658,7 +658,7 @@ walk_tree(struct got_tree_entry **next, struct got_fileindex *fileindex,
 static const struct got_error *
 diff_fileindex_tree(struct got_fileindex *fileindex,
     struct got_fileindex_entry **ie, struct got_tree_object *tree,
-    const char *path, struct got_repository *repo,
+    const char *path, const char *entry_name, struct got_repository *repo,
     struct got_fileindex_diff_tree_cb *cb, void *cb_arg)
 {
 	const struct got_error *err = NULL;
@@ -680,40 +680,58 @@ diff_fileindex_tree(struct got_fileindex *fileindex,
 			cmp = got_path_cmp((*ie)->path, te_path);
 			free(te_path);
 			if (cmp == 0) {
-				err = cb->diff_old_new(cb_arg, *ie, te,
-				    path);
-				if (err)
-					break;
+				if (got_path_is_child((*ie)->path, path,
+				    path_len) && (entry_name == NULL ||
+				    strcmp(te->name, entry_name) == 0)) {
+					err = cb->diff_old_new(cb_arg, *ie, te,
+					    path);
+					if (err || entry_name)
+						break;
+				}
 				*ie = walk_fileindex(fileindex, *ie);
 				err = walk_tree(&te, fileindex, ie, te,
-				    path, repo, cb, cb_arg);
-			} else if (cmp < 0 ) {
+				    path, entry_name, repo, cb, cb_arg);
+			} else if (cmp < 0) {
 				next = walk_fileindex(fileindex, *ie);
-				err = cb->diff_old(cb_arg, *ie, path);
-				if (err)
-					break;
+				if (got_path_is_child((*ie)->path, path,
+				    path_len) && (entry_name == NULL ||
+				    strcmp(te->name, entry_name) == 0)) {
+					err = cb->diff_old(cb_arg, *ie, path);
+					if (err || entry_name)
+						break;
+				}
 				*ie = next;
 			} else {
-				err = cb->diff_new(cb_arg, te, path);
-				if (err)
-					break;
+				if ((entry_name == NULL ||
+				    strcmp(te->name, entry_name) == 0)) {
+					err = cb->diff_new(cb_arg, te, path);
+					if (err || entry_name)
+						break;
+				}
 				err = walk_tree(&te, fileindex, ie, te,
-				    path, repo, cb, cb_arg);
+				    path, entry_name, repo, cb, cb_arg);
 			}
 			if (err)
 				break;
 		} else if (*ie) {
 			next = walk_fileindex(fileindex, *ie);
-			err = cb->diff_old(cb_arg, *ie, path);
-			if (err)
-				break;
+			if (got_path_is_child((*ie)->path, path, path_len) &&
+			    (entry_name == NULL ||
+			    strcmp(te->name, entry_name) == 0)) {
+				err = cb->diff_old(cb_arg, *ie, path);
+				if (err || entry_name)
+					break;
+			}
 			*ie = next;
 		} else if (te) {
-			err = cb->diff_new(cb_arg, te, path);
-			if (err)
-				break;
-			err = walk_tree(&te, fileindex, ie, te, path, repo, cb,
-			    cb_arg);
+			if (entry_name == NULL ||
+			    strcmp(te->name, entry_name) == 0) {
+				err = cb->diff_new(cb_arg, te, path);
+				if (err || entry_name)
+					break;
+			}
+			err = walk_tree(&te, fileindex, ie, te, path,
+			    entry_name, repo, cb, cb_arg);
 			if (err)
 				break;
 		}
@@ -724,12 +742,14 @@ diff_fileindex_tree(struct got_fileindex *fileindex,
 
 const struct got_error *
 got_fileindex_diff_tree(struct got_fileindex *fileindex,
-    struct got_tree_object *tree, struct got_repository *repo,
+    struct got_tree_object *tree, const char *path, const char *entry_name,
+    struct got_repository *repo,
     struct got_fileindex_diff_tree_cb *cb, void *cb_arg)
 {
 	struct got_fileindex_entry *min;
 	min = RB_MIN(got_fileindex_tree, &fileindex->entries);
-	return diff_fileindex_tree(fileindex, &min, tree, "", repo, cb, cb_arg);
+	return diff_fileindex_tree(fileindex, &min, tree, path, entry_name,
+	    repo, cb, cb_arg);
 }
 
 static const struct got_error *
diff --git a/lib/got_lib_fileindex.h b/lib/got_lib_fileindex.h
index 9829455..c3528c7 100644
--- a/lib/got_lib_fileindex.h
+++ b/lib/got_lib_fileindex.h
@@ -121,8 +121,8 @@ struct got_fileindex_diff_tree_cb {
 	got_fileindex_diff_tree_new_cb diff_new;
 };
 const struct got_error *got_fileindex_diff_tree(struct got_fileindex *,
-    struct got_tree_object *, struct got_repository *,
-    struct got_fileindex_diff_tree_cb *, void *);
+    struct got_tree_object *, const char *, const char *,
+    struct got_repository *, struct got_fileindex_diff_tree_cb *, void *);
 
 typedef const struct got_error *(*got_fileindex_diff_dir_old_new_cb)(void *,
     struct got_fileindex_entry *, struct dirent *, const char *);
diff --git a/lib/worktree.c b/lib/worktree.c
index 106aa6f..1c52dfc 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -1363,7 +1363,7 @@ done:
 
 
 const struct got_error *
-got_worktree_checkout_files(struct got_worktree *worktree,
+got_worktree_checkout_files(struct got_worktree *worktree, const char *path,
     struct got_repository *repo, got_worktree_checkout_cb progress_cb,
     void *progress_arg, got_worktree_cancel_cb cancel_cb, void *cancel_arg)
 {
@@ -1376,6 +1376,7 @@ got_worktree_checkout_files(struct got_worktree *worktree,
 	FILE *index = NULL, *new_index = NULL;
 	struct got_fileindex_diff_tree_cb diff_cb;
 	struct diff_cb_arg arg;
+	char *relpath = NULL, *entry_name = NULL;
 
 	err = lock_worktree(worktree, LOCK_EX);
 	if (err)
@@ -1426,15 +1427,87 @@ got_worktree_checkout_files(struct got_worktree *worktree,
 	if (err)
 		goto done;
 
-	err = got_object_id_by_path(&tree_id, repo,
-	    worktree->base_commit_id, worktree->path_prefix);
-	if (err)
-		goto done;
+	if (path[0]) {
+		char *tree_path;
+		int obj_type;
+		relpath = strdup(path);
+		if (relpath == NULL) {
+			err = got_error_from_errno();
+			goto done;
+		}
+		if (asprintf(&tree_path, "%s%s%s", worktree->path_prefix,
+		    got_path_is_root_dir(worktree->path_prefix) ? "" : "/",
+		    path) == -1) {
+			err = got_error_from_errno();
+			goto done;
+		}
+		err = got_object_id_by_path(&tree_id, repo,
+		    worktree->base_commit_id, tree_path);
+		free(tree_path);
+		if (err)
+			goto done;
+		err = got_object_get_type(&obj_type, repo, tree_id);
+		if (err)
+			goto done;
+		if (obj_type == GOT_OBJ_TYPE_BLOB) {
+			/* Split provided path into parent dir + entry name. */
+			if (strchr(path, '/')  == NULL) {
+				relpath = strdup("");
+				if (relpath == NULL) {
+					err = got_error_from_errno();
+					goto done;
+				}
+				tree_path = strdup(worktree->path_prefix);
+				if (tree_path == NULL) {
+					err = got_error_from_errno();
+					goto done;
+				}
+			} else {
+				err = got_path_dirname(&relpath, path);
+				if (err)
+					goto done;
+				if (asprintf(&tree_path, "%s%s%s",
+				    worktree->path_prefix,
+				    got_path_is_root_dir(
+				    worktree->path_prefix) ? "" : "/",
+				    relpath) == -1) {
+					err = got_error_from_errno();
+					goto done;
+				}
+			}
+			err = got_object_id_by_path(&tree_id, repo,
+			    worktree->base_commit_id, tree_path);
+			free(tree_path);
+			if (err)
+				goto done;
+			entry_name = basename(path);
+			if (entry_name == NULL) {
+				err = got_error_from_errno();
+				goto done;
+			}
+		}
+	} else {
+		relpath = strdup("");
+		if (relpath == NULL) {
+			err = got_error_from_errno();
+			goto done;
+		}
+		err = got_object_id_by_path(&tree_id, repo,
+		    worktree->base_commit_id, worktree->path_prefix);
+		if (err)
+			goto done;
+	}
 
 	err = got_object_open_as_tree(&tree, repo, tree_id);
 	if (err)
 		goto done;
 
+	if (entry_name &&
+	    got_object_tree_find_entry(tree, entry_name) == NULL) {
+		err = got_error(GOT_ERR_NO_TREE_ENTRY);
+		goto done;
+	}
+
 	diff_cb.diff_old_new = diff_old_new;
 	diff_cb.diff_old = diff_old;
 	diff_cb.diff_new = diff_new;
@@ -1445,8 +1518,8 @@ got_worktree_checkout_files(struct got_worktree *worktree,
 	arg.progress_arg = progress_arg;
 	arg.cancel_cb = cancel_cb;
 	arg.cancel_arg = cancel_arg;
-	checkout_err = got_fileindex_diff_tree(fileindex, tree, repo,
-	    &diff_cb, &arg);
+	checkout_err = got_fileindex_diff_tree(fileindex, tree, relpath,
+	    entry_name, repo, &diff_cb, &arg);
 
 	/* Try to sync the fileindex back to disk in any case. */
 	err = got_fileindex_write(fileindex, new_index);
@@ -1463,6 +1536,7 @@ got_worktree_checkout_files(struct got_worktree *worktree,
 	new_fileindex_path = NULL;
 
 done:
+	free(relpath);
 	if (tree)
 		got_object_tree_close(tree);
 	if (commit)
@@ -1694,7 +1768,8 @@ got_worktree_resolve_path(char **wt_path, struct got_worktree *worktree,
 		goto done;
 	}
 
-	path = strdup(resolved + strlen(got_worktree_get_root_path(worktree)));
+	path = strdup(resolved +
+	    strlen(got_worktree_get_root_path(worktree)) + 1 /* skip '/' */);
 	if (path == NULL) {
 		err = got_error_from_errno();
 		goto done;
diff --git a/regress/cmdline/update.sh b/regress/cmdline/update.sh
index 76a9eee..5f2aab8 100755
--- a/regress/cmdline/update.sh
+++ b/regress/cmdline/update.sh
@@ -1071,6 +1071,177 @@ function test_update_conflict_wt_rm_vs_repo_rm {
 	test_done "$testroot" "0"
 }
 
+function test_update_partial {
+	local testroot=`test_init update_partial`
+
+	got checkout $testroot/repo $testroot/wt > /dev/null
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	echo "modified alpha" > $testroot/repo/alpha
+	echo "modified beta" > $testroot/repo/beta
+	echo "modified epsilon/zeta" > $testroot/repo/epsilon/zeta
+	git_commit $testroot/repo -m "modified two files"
+
+	for f in alpha beta epsilon/zeta; do
+		echo "U  $f" > $testroot/stdout.expected
+		echo -n "Updated to commit " >> $testroot/stdout.expected
+		git_show_head $testroot/repo >> $testroot/stdout.expected
+		echo >> $testroot/stdout.expected
+
+		(cd $testroot/wt && got update $f > $testroot/stdout)
+
+		cmp $testroot/stdout.expected $testroot/stdout
+		ret="$?"
+		if [ "$ret" != "0" ]; then
+			diff -u $testroot/stdout.expected $testroot/stdout
+			test_done "$testroot" "$ret"
+			return 1
+		fi
+
+		echo "modified $f" > $testroot/content.expected
+		cat $testroot/wt/$f > $testroot/content
+
+		cmp $testroot/content.expected $testroot/content
+		ret="$?"
+		if [ "$ret" != "0" ]; then
+			diff -u $testroot/content.expected $testroot/content
+			test_done "$testroot" "$ret"
+			return 1
+		fi
+	done
+	test_done "$testroot" "$ret"
+}
+
+function test_update_partial_add {
+	local testroot=`test_init update_partial_add`
+
+	got checkout $testroot/repo $testroot/wt > /dev/null
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	echo "new" > $testroot/repo/new
+	echo "epsilon/new2" > $testroot/repo/epsilon/new2
+	(cd $testroot/repo && git add .)
+	git_commit $testroot/repo -m "added two files"
+
+	for f in new epsilon/new2; do
+		echo "A  $f" > $testroot/stdout.expected
+		echo -n "Updated to commit " >> $testroot/stdout.expected
+		git_show_head $testroot/repo >> $testroot/stdout.expected
+		echo >> $testroot/stdout.expected
+
+		(cd $testroot/wt && got update $f > $testroot/stdout)
+
+		cmp $testroot/stdout.expected $testroot/stdout
+		ret="$?"
+		if [ "$ret" != "0" ]; then
+			diff -u $testroot/stdout.expected $testroot/stdout
+			test_done "$testroot" "$ret"
+			return 1
+		fi
+
+		echo "$f" > $testroot/content.expected
+		cat $testroot/wt/$f > $testroot/content
+
+		cmp $testroot/content.expected $testroot/content
+		ret="$?"
+		if [ "$ret" != "0" ]; then
+			diff -u $testroot/content.expected $testroot/content
+			test_done "$testroot" "$ret"
+			return 1
+		fi
+	done
+	test_done "$testroot" "$ret"
+}
+
+function test_update_partial_rm {
+	local testroot=`test_init update_partial_rm`
+
+	got checkout $testroot/repo $testroot/wt > /dev/null
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	(cd $testroot/repo && git rm -q alpha)
+	(cd $testroot/repo && git rm -q epsilon/zeta)
+	git_commit $testroot/repo -m "removed two files"
+
+	for f in alpha epsilon/zeta; do
+		echo "got: no such entry found in tree" \
+			> $testroot/stderr.expected
+
+		(cd $testroot/wt && got update $f 2> $testroot/stderr)
+		ret="$?"
+		if [ "$ret" == "0" ]; then
+			echo "update succeeded unexpectedly" >&2
+			test_done "$testroot" "1"
+			return 1
+		fi
+
+		cmp $testroot/stderr.expected $testroot/stderr
+		ret="$?"
+		if [ "$ret" != "0" ]; then
+			diff -u $testroot/stderr.expected $testroot/stderr
+			test_done "$testroot" "$ret"
+			return 1
+		fi
+	done
+	test_done "$testroot" "$ret"
+}
+
+function test_update_partial_dir {
+	local testroot=`test_init update_partial_dir`
+
+	got checkout $testroot/repo $testroot/wt > /dev/null
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	echo "modified alpha" > $testroot/repo/alpha
+	echo "modified beta" > $testroot/repo/beta
+	echo "modified epsilon/zeta" > $testroot/repo/epsilon/zeta
+	git_commit $testroot/repo -m "modified two files"
+
+	echo "U  epsilon/zeta" > $testroot/stdout.expected
+	echo -n "Updated to commit " >> $testroot/stdout.expected
+	git_show_head $testroot/repo >> $testroot/stdout.expected
+	echo >> $testroot/stdout.expected
+
+	(cd $testroot/wt && got update epsilon > $testroot/stdout)
+
+	cmp $testroot/stdout.expected $testroot/stdout
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		diff -u $testroot/stdout.expected $testroot/stdout
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	echo "modified epsilon/zeta" > $testroot/content.expected
+	cat $testroot/wt/epsilon/zeta > $testroot/content
+
+	cmp $testroot/content.expected $testroot/content
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		diff -u $testroot/content.expected $testroot/content
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+	test_done "$testroot" "$ret"
+
+}
+
 run_test test_update_basic
 run_test test_update_adds_file
 run_test test_update_deletes_file
@@ -1092,3 +1263,7 @@ run_test test_update_conflict_wt_add_vs_repo_add
 run_test test_update_conflict_wt_edit_vs_repo_rm
 run_test test_update_conflict_wt_rm_vs_repo_edit
 run_test test_update_conflict_wt_rm_vs_repo_rm
+run_test test_update_partial
+run_test test_update_partial_add
+run_test test_update_partial_rm
+run_test test_update_partial_dir
diff --git a/regress/worktree/worktree_test.c b/regress/worktree/worktree_test.c
index bd0774b..1755d39 100644
--- a/regress/worktree/worktree_test.c
+++ b/regress/worktree/worktree_test.c
@@ -379,7 +379,7 @@ worktree_checkout(const char *repo_path)
 	if (err != NULL)
 		goto done;
 
-	err = got_worktree_checkout_files(worktree, repo, progress_cb, NULL,
+	err = got_worktree_checkout_files(worktree, "", repo, progress_cb, NULL,
 	    NULL, NULL);
 	if (err != NULL)
 		goto done;