2 * Copyright (c) 2017 Martin Pieuchot <mpi@openbsd.org>
3 * Copyright (c) 2018, 2019 Stefan Sperling <stsp@openbsd.org>
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #include <sys/queue.h>
19 #include <sys/limits.h>
20 #include <sys/types.h>
22 #include <sys/param.h>
37 #include "got_error.h"
38 #include "got_object.h"
39 #include "got_reference.h"
40 #include "got_repository.h"
42 #include "got_worktree.h"
44 #include "got_commit_graph.h"
45 #include "got_blame.h"
46 #include "got_privsep.h"
47 #include "got_opentemp.h"
50 #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
53 static volatile sig_atomic_t sigint_received;
54 static volatile sig_atomic_t sigpipe_received;
57 catch_sigint(int signo)
63 catch_sigpipe(int signo)
71 const struct got_error *(*cmd_main)(int, char *[]);
72 void (*cmd_usage)(void);
73 const char *cmd_descr;
76 __dead static void usage(void);
77 __dead static void usage_checkout(void);
78 __dead static void usage_update(void);
79 __dead static void usage_log(void);
80 __dead static void usage_diff(void);
81 __dead static void usage_blame(void);
82 __dead static void usage_tree(void);
83 __dead static void usage_status(void);
84 __dead static void usage_ref(void);
85 __dead static void usage_add(void);
86 __dead static void usage_rm(void);
87 __dead static void usage_revert(void);
88 __dead static void usage_commit(void);
90 static const struct got_error* cmd_checkout(int, char *[]);
91 static const struct got_error* cmd_update(int, char *[]);
92 static const struct got_error* cmd_log(int, char *[]);
93 static const struct got_error* cmd_diff(int, char *[]);
94 static const struct got_error* cmd_blame(int, char *[]);
95 static const struct got_error* cmd_tree(int, char *[]);
96 static const struct got_error* cmd_status(int, char *[]);
97 static const struct got_error* cmd_ref(int, char *[]);
98 static const struct got_error* cmd_add(int, char *[]);
99 static const struct got_error* cmd_rm(int, char *[]);
100 static const struct got_error* cmd_revert(int, char *[]);
101 static const struct got_error* cmd_commit(int, char *[]);
103 static struct cmd got_commands[] = {
104 { "checkout", cmd_checkout, usage_checkout,
105 "check out a new work tree from a repository" },
106 { "update", cmd_update, usage_update,
107 "update a work tree to a different commit" },
108 { "log", cmd_log, usage_log,
109 "show repository history" },
110 { "diff", cmd_diff, usage_diff,
111 "compare files and directories" },
112 { "blame", cmd_blame, usage_blame,
113 "show when lines in a file were changed" },
114 { "tree", cmd_tree, usage_tree,
115 "list files and directories in repository" },
116 { "status", cmd_status, usage_status,
117 "show modification status of files" },
118 { "ref", cmd_ref, usage_ref,
119 "manage references in repository" },
120 { "add", cmd_add, usage_add,
121 "add new files to version control" },
122 { "rm", cmd_rm, usage_rm,
123 "remove a versioned file" },
124 { "revert", cmd_revert, usage_revert,
125 "revert uncommitted changes" },
126 { "commit", cmd_commit, usage_commit,
127 "write changes from work tree to repository" },
131 main(int argc, char *argv[])
138 setlocale(LC_CTYPE, "");
140 while ((ch = getopt(argc, argv, "h")) != -1) {
158 signal(SIGINT, catch_sigint);
159 signal(SIGPIPE, catch_sigpipe);
161 for (i = 0; i < nitems(got_commands); i++) {
162 const struct got_error *error;
164 cmd = &got_commands[i];
166 if (strncmp(cmd->cmd_name, argv[0], strlen(argv[0])))
170 got_commands[i].cmd_usage();
172 error = got_commands[i].cmd_main(argc, argv);
173 if (error && !(sigint_received || sigpipe_received)) {
174 fprintf(stderr, "%s: %s\n", getprogname(), error->msg);
181 fprintf(stderr, "%s: unknown command '%s'\n", getprogname(), argv[0]);
190 fprintf(stderr, "usage: %s [-h] command [arg ...]\n\n"
191 "Available commands:\n", getprogname());
192 for (i = 0; i < nitems(got_commands); i++) {
193 struct cmd *cmd = &got_commands[i];
194 fprintf(stderr, " %s: %s\n", cmd->cmd_name, cmd->cmd_descr);
199 static const struct got_error *
200 get_editor(char **editorp)
204 editor = getenv("VISUAL");
206 editor = getenv("EDITOR");
210 *editorp = realpath(editor, NULL);
211 if (*editorp == NULL)
212 return got_error_from_errno("relpath");
217 static const struct got_error *
218 apply_unveil(const char *repo_path, int repo_read_only,
219 const char *worktree_path, int create_worktree,
222 const struct got_error *error;
223 static char err_msg[MAXPATHLEN + 36];
225 if (create_worktree) {
226 /* Pre-create work tree path to avoid unveiling its parents. */
227 error = got_path_mkdir(worktree_path);
229 if (errno == EEXIST) {
230 if (got_path_dir_is_empty(worktree_path)) {
234 snprintf(err_msg, sizeof(err_msg),
235 "%s: directory exists but is not empty",
237 error = got_error_msg(GOT_ERR_BAD_PATH,
242 if (error && (error->code != GOT_ERR_ERRNO || errno != EISDIR))
248 error = get_editor(&editor);
255 if (repo_path && unveil(repo_path, repo_read_only ? "r" : "rwc") != 0)
256 return got_error_from_errno2("unveil", repo_path);
258 if (worktree_path && unveil(worktree_path, "rwc") != 0)
259 return got_error_from_errno2("unveil", worktree_path);
261 if (unveil("/tmp", "rwc") != 0)
262 return got_error_from_errno2("unveil", "/tmp");
264 error = got_privsep_unveil_exec_helpers();
268 if (unveil(NULL, NULL) != 0)
269 return got_error_from_errno("unveil");
277 fprintf(stderr, "usage: %s checkout [-p prefix] repository-path "
278 "[worktree-path]\n", getprogname());
283 checkout_progress(void *arg, unsigned char status, const char *path)
285 char *worktree_path = arg;
287 while (path[0] == '/')
290 printf("%c %s/%s\n", status, worktree_path, path);
293 static const struct got_error *
294 check_cancelled(void *arg)
296 if (sigint_received || sigpipe_received)
297 return got_error(GOT_ERR_CANCELLED);
301 static const struct got_error *
302 check_linear_ancestry(struct got_worktree *worktree,
303 struct got_object_id *commit_id, struct got_repository *repo)
305 const struct got_error *err = NULL;
306 struct got_object_id *yca_id, *base_commit_id;
308 base_commit_id = got_worktree_get_base_commit_id(worktree);
309 err = got_commit_graph_find_youngest_common_ancestor(&yca_id,
310 commit_id, base_commit_id, repo);
315 return got_error(GOT_ERR_ANCESTRY);
318 * Require a straight line of history between the target commit
319 * and the work tree's base commit.
321 * Non-linear situation such as the this require a rebase:
323 * (commit) D F (base_commit)
331 * 'got update' only handles linear cases:
332 * Update forwards in time: A (base/yca) - B - C - D (commit)
333 * Update backwards in time: D (base) - C - D - A (commit/yca)
335 if (got_object_id_cmp(commit_id, yca_id) != 0 &&
336 got_object_id_cmp(base_commit_id, yca_id) != 0)
337 return got_error(GOT_ERR_ANCESTRY);
344 static const struct got_error *
345 cmd_checkout(int argc, char *argv[])
347 const struct got_error *error = NULL;
348 struct got_repository *repo = NULL;
349 struct got_reference *head_ref = NULL;
350 struct got_worktree *worktree = NULL;
351 char *repo_path = NULL;
352 char *worktree_path = NULL;
353 const char *path_prefix = "";
354 char *commit_id_str = NULL;
355 int ch, same_path_prefix;
357 while ((ch = getopt(argc, argv, "c:p:")) != -1) {
360 commit_id_str = strdup(optarg);
361 if (commit_id_str == NULL)
362 return got_error_from_errno("strdup");
365 path_prefix = optarg;
377 if (pledge("stdio rpath wpath cpath fattr flock proc exec sendfd "
378 "unveil", NULL) == -1)
382 char *cwd, *base, *dotgit;
383 repo_path = realpath(argv[0], NULL);
384 if (repo_path == NULL)
385 return got_error_from_errno2("realpath", argv[0]);
386 cwd = getcwd(NULL, 0);
388 error = got_error_from_errno("getcwd");
391 if (path_prefix[0]) {
392 base = basename(path_prefix);
394 error = got_error_from_errno2("basename",
399 base = basename(repo_path);
401 error = got_error_from_errno2("basename",
406 dotgit = strstr(base, ".git");
409 if (asprintf(&worktree_path, "%s/%s", cwd, base) == -1) {
410 error = got_error_from_errno("asprintf");
415 } else if (argc == 2) {
416 repo_path = realpath(argv[0], NULL);
417 if (repo_path == NULL) {
418 error = got_error_from_errno2("realpath", argv[0]);
421 worktree_path = realpath(argv[1], NULL);
422 if (worktree_path == NULL) {
423 error = got_error_from_errno2("realpath", argv[1]);
429 got_path_strip_trailing_slashes(repo_path);
430 got_path_strip_trailing_slashes(worktree_path);
432 error = got_repo_open(&repo, repo_path);
436 error = apply_unveil(got_repo_get_path(repo), 0, worktree_path, 1, 0);
440 error = got_ref_open(&head_ref, repo, GOT_REF_HEAD, 0);
444 error = got_worktree_init(worktree_path, head_ref, path_prefix, repo);
445 if (error != NULL && !(error->code == GOT_ERR_ERRNO && errno == EEXIST))
448 error = got_worktree_open(&worktree, worktree_path);
452 error = got_worktree_match_path_prefix(&same_path_prefix, worktree,
456 if (!same_path_prefix) {
457 error = got_error(GOT_ERR_PATH_PREFIX);
462 struct got_object_id *commit_id;
463 error = got_object_resolve_id_str(&commit_id, repo,
467 error = check_linear_ancestry(worktree, commit_id, repo);
472 error = got_worktree_set_base_commit_id(worktree, repo,
479 error = got_worktree_checkout_files(worktree, "", repo,
480 checkout_progress, worktree_path, check_cancelled, NULL);
484 printf("Now shut up and hack\n");
496 fprintf(stderr, "usage: %s update [-c commit] [path]\n",
502 update_progress(void *arg, unsigned char status, const char *path)
504 int *did_something = arg;
506 if (status == GOT_STATUS_EXISTS)
510 while (path[0] == '/')
512 printf("%c %s\n", status, path);
515 static const struct got_error *
516 cmd_update(int argc, char *argv[])
518 const struct got_error *error = NULL;
519 struct got_repository *repo = NULL;
520 struct got_worktree *worktree = NULL;
521 char *worktree_path = NULL, *path = NULL;
522 struct got_object_id *commit_id = NULL;
523 char *commit_id_str = NULL;
524 int ch, did_something = 0;
526 while ((ch = getopt(argc, argv, "c:")) != -1) {
529 commit_id_str = strdup(optarg);
530 if (commit_id_str == NULL)
531 return got_error_from_errno("strdup");
543 if (pledge("stdio rpath wpath cpath fattr flock proc exec sendfd "
544 "unveil", NULL) == -1)
547 worktree_path = getcwd(NULL, 0);
548 if (worktree_path == NULL) {
549 error = got_error_from_errno("getcwd");
552 error = got_worktree_open(&worktree, worktree_path);
559 error = got_error_from_errno("strdup");
562 } else if (argc == 1) {
563 error = got_worktree_resolve_path(&path, worktree, argv[0]);
569 error = got_repo_open(&repo, got_worktree_get_repo_path(worktree));
573 error = apply_unveil(got_repo_get_path(repo), 0,
574 got_worktree_get_root_path(worktree), 0, 0);
578 if (commit_id_str == NULL) {
579 struct got_reference *head_ref;
580 error = got_ref_open(&head_ref, repo, GOT_REF_HEAD, 0);
583 error = got_ref_resolve(&commit_id, repo, head_ref);
586 error = got_object_id_str(&commit_id_str, commit_id);
590 error = got_object_resolve_id_str(&commit_id, repo,
596 error = check_linear_ancestry(worktree, commit_id, repo);
600 if (got_object_id_cmp(got_worktree_get_base_commit_id(worktree),
602 error = got_worktree_set_base_commit_id(worktree, repo,
608 error = got_worktree_checkout_files(worktree, path, repo,
609 update_progress, &did_something, check_cancelled, NULL);
614 printf("Updated to commit %s\n", commit_id_str);
616 printf("Already up-to-date\n");
625 static const struct got_error *
626 print_patch(struct got_commit_object *commit, struct got_object_id *id,
627 int diff_context, struct got_repository *repo)
629 const struct got_error *err = NULL;
630 struct got_tree_object *tree1 = NULL, *tree2;
631 struct got_object_qid *qid;
632 char *id_str1 = NULL, *id_str2;
634 err = got_object_open_as_tree(&tree2, repo,
635 got_object_commit_get_tree_id(commit));
639 qid = SIMPLEQ_FIRST(got_object_commit_get_parent_ids(commit));
641 struct got_commit_object *pcommit;
643 err = got_object_open_as_commit(&pcommit, repo, qid->id);
647 err = got_object_open_as_tree(&tree1, repo,
648 got_object_commit_get_tree_id(pcommit));
649 got_object_commit_close(pcommit);
653 err = got_object_id_str(&id_str1, qid->id);
658 err = got_object_id_str(&id_str2, id);
662 printf("diff %s %s\n", id_str1 ? id_str1 : "/dev/null", id_str2);
663 err = got_diff_tree(tree1, tree2, "", "", diff_context, repo, stdout);
666 got_object_tree_close(tree1);
667 got_object_tree_close(tree2);
674 get_datestr(time_t *time, char *datebuf)
676 char *p, *s = ctime_r(time, datebuf);
683 static const struct got_error *
684 print_commit(struct got_commit_object *commit, struct got_object_id *id,
685 struct got_repository *repo, int show_patch, int diff_context,
686 struct got_reflist_head *refs)
688 const struct got_error *err = NULL;
689 char *id_str, *datestr, *logmsg0, *logmsg, *line;
691 time_t committer_time;
692 const char *author, *committer;
693 char *refs_str = NULL;
694 struct got_reflist_entry *re;
696 SIMPLEQ_FOREACH(re, refs, entry) {
699 if (got_object_id_cmp(re->id, id) != 0)
701 name = got_ref_get_name(re->ref);
702 if (strcmp(name, GOT_REF_HEAD) == 0)
704 if (strncmp(name, "refs/", 5) == 0)
706 if (strncmp(name, "got/", 4) == 0)
708 if (strncmp(name, "heads/", 6) == 0)
710 if (strncmp(name, "remotes/", 8) == 0)
713 if (asprintf(&refs_str, "%s%s%s", s ? s : "", s ? ", " : "",
715 err = got_error_from_errno("asprintf");
721 err = got_object_id_str(&id_str, id);
725 printf("-----------------------------------------------\n");
726 printf("commit %s%s%s%s\n", id_str, refs_str ? " (" : "",
727 refs_str ? refs_str : "", refs_str ? ")" : "");
732 printf("from: %s\n", got_object_commit_get_author(commit));
733 committer_time = got_object_commit_get_committer_time(commit);
734 datestr = get_datestr(&committer_time, datebuf);
735 printf("date: %s UTC\n", datestr);
736 author = got_object_commit_get_author(commit);
737 committer = got_object_commit_get_committer(commit);
738 if (strcmp(author, committer) != 0)
739 printf("via: %s\n", committer);
740 if (got_object_commit_get_nparents(commit) > 1) {
741 const struct got_object_id_queue *parent_ids;
742 struct got_object_qid *qid;
744 parent_ids = got_object_commit_get_parent_ids(commit);
745 SIMPLEQ_FOREACH(qid, parent_ids, entry) {
746 err = got_object_id_str(&id_str, qid->id);
749 printf("parent %d: %s\n", n++, id_str);
754 logmsg0 = strdup(got_object_commit_get_logmsg(commit));
756 return got_error_from_errno("strdup");
760 line = strsep(&logmsg, "\n");
762 printf(" %s\n", line);
767 err = print_patch(commit, id, diff_context, repo);
772 if (fflush(stdout) != 0 && err == NULL)
773 err = got_error_from_errno("fflush");
777 static const struct got_error *
778 print_commits(struct got_object_id *root_id, struct got_repository *repo,
779 char *path, int show_patch, int diff_context, int limit,
780 int first_parent_traversal, struct got_reflist_head *refs)
782 const struct got_error *err;
783 struct got_commit_graph *graph;
785 err = got_commit_graph_open(&graph, root_id, path,
786 first_parent_traversal, repo);
789 err = got_commit_graph_iter_start(graph, root_id, repo);
793 struct got_commit_object *commit;
794 struct got_object_id *id;
796 if (sigint_received || sigpipe_received)
799 err = got_commit_graph_iter_next(&id, graph);
801 if (err->code == GOT_ERR_ITER_COMPLETED) {
805 if (err->code != GOT_ERR_ITER_NEED_MORE)
807 err = got_commit_graph_fetch_commits(graph, 1, repo);
816 err = got_object_open_as_commit(&commit, repo, id);
819 err = print_commit(commit, id, repo, show_patch, diff_context,
821 got_object_commit_close(commit);
822 if (err || (limit && --limit == 0))
826 got_commit_graph_close(graph);
833 fprintf(stderr, "usage: %s log [-c commit] [-C number] [-f] [ -l N ] [-p] "
834 "[-r repository-path] [path]\n", getprogname());
838 static const struct got_error *
839 cmd_log(int argc, char *argv[])
841 const struct got_error *error;
842 struct got_repository *repo = NULL;
843 struct got_worktree *worktree = NULL;
844 struct got_commit_object *commit = NULL;
845 struct got_object_id *id = NULL;
846 char *repo_path = NULL, *path = NULL, *cwd = NULL, *in_repo_path = NULL;
847 char *start_commit = NULL;
848 int diff_context = 3, ch;
849 int show_patch = 0, limit = 0, first_parent_traversal = 0;
851 struct got_reflist_head refs;
856 if (pledge("stdio rpath wpath cpath flock proc exec sendfd unveil",
862 while ((ch = getopt(argc, argv, "pc:C:l:fr:")) != -1) {
868 start_commit = optarg;
871 diff_context = strtonum(optarg, 0, GOT_DIFF_MAX_CONTEXT,
874 err(1, "-C option %s", errstr);
877 limit = strtonum(optarg, 1, INT_MAX, &errstr);
879 err(1, "-l option %s", errstr);
882 first_parent_traversal = 1;
885 repo_path = realpath(optarg, NULL);
886 if (repo_path == NULL)
888 got_path_strip_trailing_slashes(repo_path);
899 cwd = getcwd(NULL, 0);
901 error = got_error_from_errno("getcwd");
905 error = got_worktree_open(&worktree, cwd);
906 if (error && error->code != GOT_ERR_NOT_WORKTREE)
913 error = got_error_from_errno("strdup");
916 } else if (argc == 1) {
918 error = got_worktree_resolve_path(&path, worktree,
923 path = strdup(argv[0]);
925 error = got_error_from_errno("strdup");
932 if (repo_path == NULL) {
933 repo_path = worktree ?
934 strdup(got_worktree_get_repo_path(worktree)) : strdup(cwd);
936 if (repo_path == NULL) {
937 error = got_error_from_errno("strdup");
941 error = got_repo_open(&repo, repo_path);
945 error = apply_unveil(got_repo_get_path(repo), 1,
946 worktree ? got_worktree_get_root_path(worktree) : NULL, 0, 0);
950 if (start_commit == NULL) {
951 struct got_reference *head_ref;
952 error = got_ref_open(&head_ref, repo, GOT_REF_HEAD, 0);
955 error = got_ref_resolve(&id, repo, head_ref);
956 got_ref_close(head_ref);
959 error = got_object_open_as_commit(&commit, repo, id);
961 struct got_reference *ref;
962 error = got_ref_open(&ref, repo, start_commit, 0);
965 error = got_ref_resolve(&id, repo, ref);
969 error = got_object_get_type(&obj_type, repo, id);
972 if (obj_type == GOT_OBJ_TYPE_TAG) {
973 struct got_tag_object *tag;
974 error = got_object_open_as_tag(&tag, repo, id);
977 if (got_object_tag_get_object_type(tag) !=
978 GOT_OBJ_TYPE_COMMIT) {
979 got_object_tag_close(tag);
980 error = got_error(GOT_ERR_OBJ_TYPE);
984 id = got_object_id_dup(
985 got_object_tag_get_object_id(tag));
987 error = got_error_from_errno(
988 "got_object_id_dup");
989 got_object_tag_close(tag);
992 } else if (obj_type != GOT_OBJ_TYPE_COMMIT) {
993 error = got_error(GOT_ERR_OBJ_TYPE);
996 error = got_object_open_as_commit(&commit, repo, id);
1000 if (commit == NULL) {
1001 error = got_object_resolve_id_str(&id, repo,
1010 error = got_repo_map_path(&in_repo_path, repo, path, 1);
1015 path = in_repo_path;
1018 error = got_ref_list(&refs, repo);
1022 error = print_commits(id, repo, path, show_patch,
1023 diff_context, limit, first_parent_traversal, &refs);
1030 got_worktree_close(worktree);
1032 const struct got_error *repo_error;
1033 repo_error = got_repo_close(repo);
1037 got_ref_list_free(&refs);
1044 fprintf(stderr, "usage: %s diff [-C number] [-r repository-path] "
1045 "[object1 object2 | path]\n", getprogname());
1049 struct print_diff_arg {
1050 struct got_repository *repo;
1051 struct got_worktree *worktree;
1057 static const struct got_error *
1058 print_diff(void *arg, unsigned char status, const char *path,
1059 struct got_object_id *id)
1061 struct print_diff_arg *a = arg;
1062 const struct got_error *err = NULL;
1063 struct got_blob_object *blob1 = NULL;
1065 char *abspath = NULL;
1068 if (status != GOT_STATUS_MODIFY && status != GOT_STATUS_ADD &&
1069 status != GOT_STATUS_DELETE && status != GOT_STATUS_CONFLICT)
1072 if (!a->header_shown) {
1073 printf("diff %s %s\n", a->id_str,
1074 got_worktree_get_root_path(a->worktree));
1075 a->header_shown = 1;
1078 if (status != GOT_STATUS_ADD) {
1079 err = got_object_open_as_blob(&blob1, a->repo, id, 8192);
1085 if (status != GOT_STATUS_DELETE) {
1086 if (asprintf(&abspath, "%s/%s",
1087 got_worktree_get_root_path(a->worktree), path) == -1) {
1088 err = got_error_from_errno("asprintf");
1092 f2 = fopen(abspath, "r");
1094 err = got_error_from_errno2("fopen", abspath);
1097 if (lstat(abspath, &sb) == -1) {
1098 err = got_error_from_errno2("lstat", abspath);
1104 err = got_diff_blob_file(blob1, f2, sb.st_size, path, a->diff_context,
1108 got_object_blob_close(blob1);
1109 if (f2 && fclose(f2) != 0 && err == NULL)
1110 err = got_error_from_errno("fclose");
1115 static const struct got_error *
1116 cmd_diff(int argc, char *argv[])
1118 const struct got_error *error;
1119 struct got_repository *repo = NULL;
1120 struct got_worktree *worktree = NULL;
1121 char *cwd = NULL, *repo_path = NULL;
1122 struct got_object_id *id1 = NULL, *id2 = NULL;
1123 char *id_str1 = NULL, *id_str2 = NULL;
1125 int diff_context = 3, ch;
1130 if (pledge("stdio rpath wpath cpath flock proc exec sendfd unveil",
1135 while ((ch = getopt(argc, argv, "C:r:")) != -1) {
1138 diff_context = strtonum(optarg, 1, INT_MAX, &errstr);
1140 err(1, "-C option %s", errstr);
1143 repo_path = realpath(optarg, NULL);
1144 if (repo_path == NULL)
1145 err(1, "-r option");
1146 got_path_strip_trailing_slashes(repo_path);
1157 cwd = getcwd(NULL, 0);
1159 error = got_error_from_errno("getcwd");
1162 error = got_worktree_open(&worktree, cwd);
1163 if (error && error->code != GOT_ERR_NOT_WORKTREE)
1166 if (worktree == NULL) {
1167 error = got_error(GOT_ERR_NOT_WORKTREE);
1172 "-r option can't be used when diffing a work tree");
1173 repo_path = strdup(got_worktree_get_repo_path(worktree));
1174 if (repo_path == NULL) {
1175 error = got_error_from_errno("strdup");
1179 error = got_worktree_resolve_path(&path, worktree,
1186 error = got_error_from_errno("strdup");
1190 } else if (argc == 2) {
1196 if (repo_path == NULL) {
1197 repo_path = getcwd(NULL, 0);
1198 if (repo_path == NULL)
1199 return got_error_from_errno("getcwd");
1202 error = got_repo_open(&repo, repo_path);
1207 error = apply_unveil(got_repo_get_path(repo), 1,
1208 worktree ? got_worktree_get_root_path(worktree) : NULL, 0, 0);
1213 struct print_diff_arg arg;
1215 error = got_object_id_str(&id_str,
1216 got_worktree_get_base_commit_id(worktree));
1220 arg.worktree = worktree;
1221 arg.diff_context = diff_context;
1222 arg.id_str = id_str;
1223 arg.header_shown = 0;
1225 error = got_worktree_status(worktree, path, repo, print_diff,
1226 &arg, check_cancelled, NULL);
1231 error = got_object_resolve_id_str(&id1, repo, id_str1);
1235 error = got_object_resolve_id_str(&id2, repo, id_str2);
1239 error = got_object_get_type(&type1, repo, id1);
1243 error = got_object_get_type(&type2, repo, id2);
1247 if (type1 != type2) {
1248 error = got_error(GOT_ERR_OBJ_TYPE);
1253 case GOT_OBJ_TYPE_BLOB:
1254 error = got_diff_objects_as_blobs(id1, id2, NULL, NULL,
1255 diff_context, repo, stdout);
1257 case GOT_OBJ_TYPE_TREE:
1258 error = got_diff_objects_as_trees(id1, id2, "", "",
1259 diff_context, repo, stdout);
1261 case GOT_OBJ_TYPE_COMMIT:
1262 printf("diff %s %s\n", id_str1 ? id_str1 : "/dev/null",
1264 error = got_diff_objects_as_commits(id1, id2, diff_context,
1268 error = got_error(GOT_ERR_OBJ_TYPE);
1276 got_worktree_close(worktree);
1278 const struct got_error *repo_error;
1279 repo_error = got_repo_close(repo);
1290 "usage: %s blame [-c commit] [-r repository-path] path\n",
1295 static const struct got_error *
1296 cmd_blame(int argc, char *argv[])
1298 const struct got_error *error;
1299 struct got_repository *repo = NULL;
1300 struct got_worktree *worktree = NULL;
1301 char *path, *cwd = NULL, *repo_path = NULL, *in_repo_path = NULL;
1302 struct got_object_id *commit_id = NULL;
1303 char *commit_id_str = NULL;
1307 if (pledge("stdio rpath wpath cpath flock proc exec sendfd unveil",
1312 while ((ch = getopt(argc, argv, "c:r:")) != -1) {
1315 commit_id_str = optarg;
1318 repo_path = realpath(optarg, NULL);
1319 if (repo_path == NULL)
1320 err(1, "-r option");
1321 got_path_strip_trailing_slashes(repo_path);
1337 cwd = getcwd(NULL, 0);
1339 error = got_error_from_errno("getcwd");
1342 if (repo_path == NULL) {
1343 error = got_worktree_open(&worktree, cwd);
1344 if (error && error->code != GOT_ERR_NOT_WORKTREE)
1350 strdup(got_worktree_get_repo_path(worktree));
1351 if (repo_path == NULL)
1352 error = got_error_from_errno("strdup");
1356 repo_path = strdup(cwd);
1357 if (repo_path == NULL) {
1358 error = got_error_from_errno("strdup");
1364 error = got_repo_open(&repo, repo_path);
1368 error = apply_unveil(got_repo_get_path(repo), 1, NULL, 0, 0);
1373 const char *prefix = got_worktree_get_path_prefix(worktree);
1374 char *p, *worktree_subdir = cwd +
1375 strlen(got_worktree_get_root_path(worktree));
1376 if (asprintf(&p, "%s%s%s%s%s",
1377 prefix, (strcmp(prefix, "/") != 0) ? "/" : "",
1378 worktree_subdir, worktree_subdir[0] ? "/" : "",
1380 error = got_error_from_errno("asprintf");
1383 error = got_repo_map_path(&in_repo_path, repo, p, 0);
1386 error = got_repo_map_path(&in_repo_path, repo, path, 1);
1391 if (commit_id_str == NULL) {
1392 struct got_reference *head_ref;
1393 error = got_ref_open(&head_ref, repo, GOT_REF_HEAD, 0);
1396 error = got_ref_resolve(&commit_id, repo, head_ref);
1397 got_ref_close(head_ref);
1401 error = got_object_resolve_id_str(&commit_id, repo,
1407 error = got_blame(in_repo_path, commit_id, repo, stdout);
1414 got_worktree_close(worktree);
1416 const struct got_error *repo_error;
1417 repo_error = got_repo_close(repo);
1428 "usage: %s tree [-c commit] [-r repository-path] [-iR] path\n",
1434 print_entry(struct got_tree_entry *te, const char *id, const char *path,
1435 const char *root_path)
1437 int is_root_path = (strcmp(path, root_path) == 0);
1439 path += strlen(root_path);
1440 while (path[0] == '/')
1443 printf("%s%s%s%s%s\n", id ? id : "", path,
1444 is_root_path ? "" : "/", te->name,
1445 S_ISDIR(te->mode) ? "/" : ((te->mode & S_IXUSR) ? "*" : ""));
1448 static const struct got_error *
1449 print_tree(const char *path, struct got_object_id *commit_id,
1450 int show_ids, int recurse, const char *root_path,
1451 struct got_repository *repo)
1453 const struct got_error *err = NULL;
1454 struct got_object_id *tree_id = NULL;
1455 struct got_tree_object *tree = NULL;
1456 const struct got_tree_entries *entries;
1457 struct got_tree_entry *te;
1459 err = got_object_id_by_path(&tree_id, repo, commit_id, path);
1463 err = got_object_open_as_tree(&tree, repo, tree_id);
1466 entries = got_object_tree_get_entries(tree);
1467 te = SIMPLEQ_FIRST(&entries->head);
1471 if (sigint_received || sigpipe_received)
1476 err = got_object_id_str(&id_str, te->id);
1479 if (asprintf(&id, "%s ", id_str) == -1) {
1480 err = got_error_from_errno("asprintf");
1486 print_entry(te, id, path, root_path);
1489 if (recurse && S_ISDIR(te->mode)) {
1491 if (asprintf(&child_path, "%s%s%s", path,
1492 path[0] == '/' && path[1] == '\0' ? "" : "/",
1494 err = got_error_from_errno("asprintf");
1497 err = print_tree(child_path, commit_id, show_ids, 1,
1504 te = SIMPLEQ_NEXT(te, entry);
1508 got_object_tree_close(tree);
1513 static const struct got_error *
1514 cmd_tree(int argc, char *argv[])
1516 const struct got_error *error;
1517 struct got_repository *repo = NULL;
1518 struct got_worktree *worktree = NULL;
1520 char *cwd = NULL, *repo_path = NULL, *in_repo_path = NULL;
1521 struct got_object_id *commit_id = NULL;
1522 char *commit_id_str = NULL;
1523 int show_ids = 0, recurse = 0;
1527 if (pledge("stdio rpath wpath cpath flock proc exec sendfd unveil",
1532 while ((ch = getopt(argc, argv, "c:r:iR")) != -1) {
1535 commit_id_str = optarg;
1538 repo_path = realpath(optarg, NULL);
1539 if (repo_path == NULL)
1540 err(1, "-r option");
1541 got_path_strip_trailing_slashes(repo_path);
1565 cwd = getcwd(NULL, 0);
1567 error = got_error_from_errno("getcwd");
1570 if (repo_path == NULL) {
1571 error = got_worktree_open(&worktree, cwd);
1572 if (error && error->code != GOT_ERR_NOT_WORKTREE)
1578 strdup(got_worktree_get_repo_path(worktree));
1579 if (repo_path == NULL)
1580 error = got_error_from_errno("strdup");
1584 repo_path = strdup(cwd);
1585 if (repo_path == NULL) {
1586 error = got_error_from_errno("strdup");
1592 error = got_repo_open(&repo, repo_path);
1596 error = apply_unveil(got_repo_get_path(repo), 1, NULL, 0, 0);
1602 char *p, *worktree_subdir = cwd +
1603 strlen(got_worktree_get_root_path(worktree));
1604 if (asprintf(&p, "%s/%s",
1605 got_worktree_get_path_prefix(worktree),
1606 worktree_subdir) == -1) {
1607 error = got_error_from_errno("asprintf");
1610 error = got_repo_map_path(&in_repo_path, repo, p, 1);
1617 if (in_repo_path == NULL) {
1618 error = got_repo_map_path(&in_repo_path, repo, path, 1);
1623 if (commit_id_str == NULL) {
1624 struct got_reference *head_ref;
1625 error = got_ref_open(&head_ref, repo, GOT_REF_HEAD, 0);
1628 error = got_ref_resolve(&commit_id, repo, head_ref);
1629 got_ref_close(head_ref);
1633 error = got_object_resolve_id_str(&commit_id, repo,
1639 error = print_tree(in_repo_path, commit_id, show_ids, recurse,
1640 in_repo_path, repo);
1647 got_worktree_close(worktree);
1649 const struct got_error *repo_error;
1650 repo_error = got_repo_close(repo);
1660 fprintf(stderr, "usage: %s status [path]\n", getprogname());
1664 static const struct got_error *
1665 print_status(void *arg, unsigned char status, const char *path,
1666 struct got_object_id *id)
1668 printf("%c %s\n", status, path);
1672 static const struct got_error *
1673 cmd_status(int argc, char *argv[])
1675 const struct got_error *error = NULL;
1676 struct got_repository *repo = NULL;
1677 struct got_worktree *worktree = NULL;
1678 char *cwd = NULL, *path = NULL;
1681 while ((ch = getopt(argc, argv, "")) != -1) {
1693 if (pledge("stdio rpath wpath cpath flock proc exec sendfd unveil",
1697 cwd = getcwd(NULL, 0);
1699 error = got_error_from_errno("getcwd");
1703 error = got_worktree_open(&worktree, cwd);
1710 error = got_error_from_errno("strdup");
1713 } else if (argc == 1) {
1714 error = got_worktree_resolve_path(&path, worktree, argv[0]);
1720 error = got_repo_open(&repo, got_worktree_get_repo_path(worktree));
1724 error = apply_unveil(got_repo_get_path(repo), 1,
1725 got_worktree_get_root_path(worktree), 0, 0);
1729 error = got_worktree_status(worktree, path, repo, print_status, NULL,
1730 check_cancelled, NULL);
1741 "usage: %s ref [-r repository] -l | -d name | name object\n",
1746 static const struct got_error *
1747 list_refs(struct got_repository *repo)
1749 static const struct got_error *err = NULL;
1750 struct got_reflist_head refs;
1751 struct got_reflist_entry *re;
1753 SIMPLEQ_INIT(&refs);
1754 err = got_ref_list(&refs, repo);
1758 SIMPLEQ_FOREACH(re, &refs, entry) {
1760 refstr = got_ref_to_str(re->ref);
1762 return got_error_from_errno("got_ref_to_str");
1763 printf("%s: %s\n", got_ref_get_name(re->ref), refstr);
1767 got_ref_list_free(&refs);
1771 static const struct got_error *
1772 delete_ref(struct got_repository *repo, const char *refname)
1774 const struct got_error *err = NULL;
1775 struct got_reference *ref;
1777 err = got_ref_open(&ref, repo, refname, 0);
1781 err = got_ref_delete(ref, repo);
1786 static const struct got_error *
1787 add_ref(struct got_repository *repo, const char *refname, const char *id_str)
1789 const struct got_error *err = NULL;
1790 struct got_object_id *id;
1791 struct got_reference *ref = NULL;
1793 err = got_object_resolve_id_str(&id, repo, id_str);
1797 err = got_ref_alloc(&ref, refname, id);
1801 err = got_ref_write(ref, repo);
1809 static const struct got_error *
1810 cmd_ref(int argc, char *argv[])
1812 const struct got_error *error = NULL;
1813 struct got_repository *repo = NULL;
1814 struct got_worktree *worktree = NULL;
1815 char *cwd = NULL, *repo_path = NULL;
1816 int ch, do_list = 0;
1817 const char *delref = NULL;
1819 /* TODO: Add -s option for adding symbolic references. */
1820 while ((ch = getopt(argc, argv, "d:r:l")) != -1) {
1826 repo_path = realpath(optarg, NULL);
1827 if (repo_path == NULL)
1828 err(1, "-r option");
1829 got_path_strip_trailing_slashes(repo_path);
1840 if (do_list && delref)
1841 errx(1, "-l and -d options are mutually exclusive\n");
1846 if (do_list || delref) {
1849 } else if (argc != 2)
1854 if (pledge("stdio rpath wpath flock proc exec sendfd unveil",
1858 if (pledge("stdio rpath wpath cpath fattr flock proc exec "
1859 "sendfd unveil", NULL) == -1)
1863 cwd = getcwd(NULL, 0);
1865 error = got_error_from_errno("getcwd");
1869 if (repo_path == NULL) {
1870 error = got_worktree_open(&worktree, cwd);
1871 if (error && error->code != GOT_ERR_NOT_WORKTREE)
1877 strdup(got_worktree_get_repo_path(worktree));
1878 if (repo_path == NULL)
1879 error = got_error_from_errno("strdup");
1883 repo_path = strdup(cwd);
1884 if (repo_path == NULL) {
1885 error = got_error_from_errno("strdup");
1891 error = got_repo_open(&repo, repo_path);
1895 error = apply_unveil(got_repo_get_path(repo), do_list,
1896 worktree ? got_worktree_get_root_path(worktree) : NULL, 0, 0);
1901 error = list_refs(repo);
1903 error = delete_ref(repo, delref);
1905 error = add_ref(repo, argv[0], argv[1]);
1908 got_repo_close(repo);
1910 got_worktree_close(worktree);
1919 fprintf(stderr, "usage: %s add file-path ...\n", getprogname());
1923 static const struct got_error *
1924 cmd_add(int argc, char *argv[])
1926 const struct got_error *error = NULL;
1927 struct got_repository *repo = NULL;
1928 struct got_worktree *worktree = NULL;
1930 struct got_pathlist_head paths;
1931 struct got_pathlist_entry *pe;
1936 while ((ch = getopt(argc, argv, "")) != -1) {
1950 /* make sure each file exists before doing anything halfway */
1951 for (x = 0; x < argc; x++) {
1952 char *path = realpath(argv[x], NULL);
1954 error = got_error_from_errno2("realpath", argv[x]);
1960 cwd = getcwd(NULL, 0);
1962 error = got_error_from_errno("getcwd");
1966 error = got_worktree_open(&worktree, cwd);
1970 error = got_repo_open(&repo, got_worktree_get_repo_path(worktree));
1974 error = apply_unveil(got_repo_get_path(repo), 1,
1975 got_worktree_get_root_path(worktree), 0, 0);
1979 for (x = 0; x < argc; x++) {
1980 char *path = realpath(argv[x], NULL);
1982 error = got_error_from_errno2("realpath", argv[x]);
1986 got_path_strip_trailing_slashes(path);
1987 error = got_pathlist_insert(&pe, &paths, path, NULL);
1993 error = got_worktree_schedule_add(worktree, &paths, print_status,
1997 got_repo_close(repo);
1999 got_worktree_close(worktree);
2000 TAILQ_FOREACH(pe, &paths, entry)
2001 free((char *)pe->path);
2002 got_pathlist_free(&paths);
2010 fprintf(stderr, "usage: %s rm [-f] file-path\n", getprogname());
2014 static const struct got_error *
2015 cmd_rm(int argc, char *argv[])
2017 const struct got_error *error = NULL;
2018 struct got_worktree *worktree = NULL;
2019 struct got_repository *repo = NULL;
2020 char *cwd = NULL, *path = NULL;
2021 int ch, delete_local_mods = 0;
2023 while ((ch = getopt(argc, argv, "f")) != -1) {
2026 delete_local_mods = 1;
2040 path = realpath(argv[0], NULL);
2042 error = got_error_from_errno2("realpath", argv[0]);
2045 got_path_strip_trailing_slashes(path);
2047 cwd = getcwd(NULL, 0);
2049 error = got_error_from_errno("getcwd");
2052 error = got_worktree_open(&worktree, cwd);
2056 error = got_repo_open(&repo, got_worktree_get_repo_path(worktree));
2060 error = apply_unveil(got_repo_get_path(repo), 1,
2061 got_worktree_get_root_path(worktree), 0, 0);
2065 error = got_worktree_schedule_delete(worktree, path, delete_local_mods,
2066 print_status, NULL, repo);
2071 got_repo_close(repo);
2073 got_worktree_close(worktree);
2082 fprintf(stderr, "usage: %s revert file-path\n", getprogname());
2087 revert_progress(void *arg, unsigned char status, const char *path)
2089 while (path[0] == '/')
2091 printf("%c %s\n", status, path);
2094 static const struct got_error *
2095 cmd_revert(int argc, char *argv[])
2097 const struct got_error *error = NULL;
2098 struct got_worktree *worktree = NULL;
2099 struct got_repository *repo = NULL;
2100 char *cwd = NULL, *path = NULL;
2103 while ((ch = getopt(argc, argv, "")) != -1) {
2117 path = realpath(argv[0], NULL);
2119 error = got_error_from_errno2("realpath", argv[0]);
2122 got_path_strip_trailing_slashes(path);
2124 cwd = getcwd(NULL, 0);
2126 error = got_error_from_errno("getcwd");
2129 error = got_worktree_open(&worktree, cwd);
2133 error = got_repo_open(&repo, got_worktree_get_repo_path(worktree));
2137 error = apply_unveil(got_repo_get_path(repo), 1,
2138 got_worktree_get_root_path(worktree), 0, 0);
2142 error = got_worktree_revert(worktree, path,
2143 revert_progress, NULL, repo);
2148 got_repo_close(repo);
2150 got_worktree_close(worktree);
2159 fprintf(stderr, "usage: %s commit [-m msg] file-path\n", getprogname());
2164 spawn_editor(const char *editor, const char *file)
2167 sig_t sighup, sigint, sigquit;
2170 sighup = signal(SIGHUP, SIG_IGN);
2171 sigint = signal(SIGINT, SIG_IGN);
2172 sigquit = signal(SIGQUIT, SIG_IGN);
2174 switch (pid = fork()) {
2178 execl(editor, editor, file, (char *)NULL);
2182 while (waitpid(pid, &st, 0) == -1)
2187 (void)signal(SIGHUP, sighup);
2188 (void)signal(SIGINT, sigint);
2189 (void)signal(SIGQUIT, sigquit);
2191 if (!WIFEXITED(st)) {
2196 return WEXITSTATUS(st);
2199 struct collect_commit_logmsg_arg {
2200 const char *cmdline_log;
2202 const char *worktree_path;
2207 static const struct got_error *
2208 collect_commit_logmsg(struct got_pathlist_head *commitable_paths, char **logmsg,
2211 const char *initial_content = "\n# changes to be committed:\n";
2212 struct got_pathlist_entry *pe;
2213 const struct got_error *err = NULL;
2214 char *template = NULL;
2215 struct collect_commit_logmsg_arg *a = arg;
2217 struct stat st, st2;
2220 int fd, content_changed = 0;
2222 /* if a message was specified on the command line, just use it */
2223 if (a->cmdline_log != NULL && strlen(a->cmdline_log) != 0) {
2224 len = strlen(a->cmdline_log) + 1;
2225 *logmsg = malloc(len + 1);
2226 if (*logmsg == NULL)
2227 return got_error_from_errno("malloc");
2228 strlcpy(*logmsg, a->cmdline_log, len);
2232 if (asprintf(&template, "%s/logmsg", a->worktree_path) == -1)
2233 return got_error_from_errno("asprintf");
2235 err = got_opentemp_named_fd(&a->logmsg_path, &fd, template);
2239 dprintf(fd, initial_content);
2241 TAILQ_FOREACH(pe, commitable_paths, entry) {
2242 struct got_commitable *ct = pe->data;
2243 dprintf(fd, "# %c %s\n", ct->status, pe->path);
2247 if (stat(a->logmsg_path, &st) == -1) {
2248 err = got_error_from_errno2("stat", a->logmsg_path);
2252 if (spawn_editor(a->editor, a->logmsg_path) == -1) {
2253 err = got_error_from_errno("failed spawning editor");
2257 if (stat(a->logmsg_path, &st2) == -1) {
2258 err = got_error_from_errno("stat");
2262 if (st.st_mtime == st2.st_mtime && st.st_size == st2.st_size) {
2263 unlink(a->logmsg_path);
2264 free(a->logmsg_path);
2265 a->logmsg_path = NULL;
2266 err = got_error_msg(GOT_ERR_COMMIT_MSG_EMPTY,
2267 "no changes made to commit message, aborting");
2271 /* remove comments */
2272 *logmsg = malloc(st2.st_size + 1);
2273 if (*logmsg == NULL) {
2274 err = got_error_from_errno("malloc");
2279 fp = fopen(a->logmsg_path, "r");
2280 while (fgets(buf, sizeof(buf), fp) != NULL) {
2281 if (!content_changed && strcmp(buf, initial_content) != 0)
2282 content_changed = 1;
2283 if (buf[0] == '#' || (len == 0 && buf[0] == '\n'))
2285 len = strlcat(*logmsg, buf, st2.st_size);
2289 while (len > 0 && (*logmsg)[len - 1] == '\n') {
2290 (*logmsg)[len - 1] = '\0';
2294 if (len == 0 || !content_changed) {
2295 unlink(a->logmsg_path);
2296 free(a->logmsg_path);
2297 a->logmsg_path = NULL;
2298 err = got_error_msg(GOT_ERR_COMMIT_MSG_EMPTY,
2299 "commit message cannot be empty, aborting");
2307 static const struct got_error *
2308 cmd_commit(int argc, char *argv[])
2310 const struct got_error *error = NULL;
2311 struct got_worktree *worktree = NULL;
2312 struct got_repository *repo = NULL;
2313 char *cwd = NULL, *path = NULL, *id_str = NULL;
2314 struct got_object_id *id = NULL;
2315 const char *logmsg = NULL;
2316 const char *got_author = getenv("GOT_AUTHOR");
2317 struct collect_commit_logmsg_arg cl_arg;
2318 char *editor = NULL;
2321 while ((ch = getopt(argc, argv, "m:")) != -1) {
2336 path = realpath(argv[0], NULL);
2338 error = got_error_from_errno2("realpath", argv[0]);
2341 got_path_strip_trailing_slashes(path);
2342 } else if (argc != 0)
2345 if (got_author == NULL) {
2346 /* TODO: Look current user up in password database */
2347 error = got_error(GOT_ERR_COMMIT_NO_AUTHOR);
2351 cwd = getcwd(NULL, 0);
2353 error = got_error_from_errno("getcwd");
2356 error = got_worktree_open(&worktree, cwd);
2360 error = got_repo_open(&repo, got_worktree_get_repo_path(worktree));
2364 error = apply_unveil(got_repo_get_path(repo), 0,
2365 got_worktree_get_root_path(worktree), 0, 1);
2369 error = get_editor(&editor);
2372 cl_arg.editor = editor;
2373 cl_arg.cmdline_log = logmsg;
2374 cl_arg.worktree_path = got_worktree_get_root_path(worktree);
2375 cl_arg.logmsg_path = NULL;
2376 error = got_worktree_commit(&id, worktree, path, got_author, NULL,
2377 collect_commit_logmsg, &cl_arg, print_status, NULL, repo);
2379 if (cl_arg.logmsg_path)
2380 fprintf(stderr, "%s: log message preserved in %s\n",
2381 getprogname(), cl_arg.logmsg_path);
2385 if (cl_arg.logmsg_path)
2386 unlink(cl_arg.logmsg_path);
2388 error = got_object_id_str(&id_str, id);
2391 printf("created commit %s\n", id_str);
2394 got_repo_close(repo);
2396 got_worktree_close(worktree);