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 *err;
223 static char err_msg[MAXPATHLEN + 36];
225 if (create_worktree) {
226 /* Pre-create work tree path to avoid unveiling its parents. */
227 err = 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 err = got_error_msg(GOT_ERR_BAD_PATH,
242 if (err && (err->code != GOT_ERR_ERRNO || errno != EISDIR))
248 err = get_editor(&editor);
251 if (unveil(editor, "x") != 0) {
252 err = got_error_from_errno2("unveil", editor);
259 if (repo_path && unveil(repo_path, repo_read_only ? "r" : "rwc") != 0)
260 return got_error_from_errno2("unveil", repo_path);
262 if (worktree_path && unveil(worktree_path, "rwc") != 0)
263 return got_error_from_errno2("unveil", worktree_path);
265 if (unveil("/tmp", "rwc") != 0)
266 return got_error_from_errno2("unveil", "/tmp");
268 err = got_privsep_unveil_exec_helpers();
272 if (unveil(NULL, NULL) != 0)
273 return got_error_from_errno("unveil");
281 fprintf(stderr, "usage: %s checkout [-p prefix] repository-path "
282 "[worktree-path]\n", getprogname());
287 checkout_progress(void *arg, unsigned char status, const char *path)
289 char *worktree_path = arg;
291 while (path[0] == '/')
294 printf("%c %s/%s\n", status, worktree_path, path);
297 static const struct got_error *
298 check_cancelled(void *arg)
300 if (sigint_received || sigpipe_received)
301 return got_error(GOT_ERR_CANCELLED);
305 static const struct got_error *
306 check_linear_ancestry(struct got_worktree *worktree,
307 struct got_object_id *commit_id, struct got_repository *repo)
309 const struct got_error *err = NULL;
310 struct got_object_id *yca_id, *base_commit_id;
312 base_commit_id = got_worktree_get_base_commit_id(worktree);
313 err = got_commit_graph_find_youngest_common_ancestor(&yca_id,
314 commit_id, base_commit_id, repo);
319 return got_error(GOT_ERR_ANCESTRY);
322 * Require a straight line of history between the target commit
323 * and the work tree's base commit.
325 * Non-linear situation such as the this require a rebase:
327 * (commit) D F (base_commit)
335 * 'got update' only handles linear cases:
336 * Update forwards in time: A (base/yca) - B - C - D (commit)
337 * Update backwards in time: D (base) - C - D - A (commit/yca)
339 if (got_object_id_cmp(commit_id, yca_id) != 0 &&
340 got_object_id_cmp(base_commit_id, yca_id) != 0)
341 return got_error(GOT_ERR_ANCESTRY);
348 static const struct got_error *
349 cmd_checkout(int argc, char *argv[])
351 const struct got_error *error = NULL;
352 struct got_repository *repo = NULL;
353 struct got_reference *head_ref = NULL;
354 struct got_worktree *worktree = NULL;
355 char *repo_path = NULL;
356 char *worktree_path = NULL;
357 const char *path_prefix = "";
358 char *commit_id_str = NULL;
359 int ch, same_path_prefix;
361 while ((ch = getopt(argc, argv, "c:p:")) != -1) {
364 commit_id_str = strdup(optarg);
365 if (commit_id_str == NULL)
366 return got_error_from_errno("strdup");
369 path_prefix = optarg;
381 if (pledge("stdio rpath wpath cpath fattr flock proc exec sendfd "
382 "unveil", NULL) == -1)
386 char *cwd, *base, *dotgit;
387 repo_path = realpath(argv[0], NULL);
388 if (repo_path == NULL)
389 return got_error_from_errno2("realpath", argv[0]);
390 cwd = getcwd(NULL, 0);
392 error = got_error_from_errno("getcwd");
395 if (path_prefix[0]) {
396 base = basename(path_prefix);
398 error = got_error_from_errno2("basename",
403 base = basename(repo_path);
405 error = got_error_from_errno2("basename",
410 dotgit = strstr(base, ".git");
413 if (asprintf(&worktree_path, "%s/%s", cwd, base) == -1) {
414 error = got_error_from_errno("asprintf");
419 } else if (argc == 2) {
420 repo_path = realpath(argv[0], NULL);
421 if (repo_path == NULL) {
422 error = got_error_from_errno2("realpath", argv[0]);
425 worktree_path = realpath(argv[1], NULL);
426 if (worktree_path == NULL) {
427 error = got_error_from_errno2("realpath", argv[1]);
433 got_path_strip_trailing_slashes(repo_path);
434 got_path_strip_trailing_slashes(worktree_path);
436 error = got_repo_open(&repo, repo_path);
440 error = apply_unveil(got_repo_get_path(repo), 0, worktree_path, 1, 0);
444 error = got_ref_open(&head_ref, repo, GOT_REF_HEAD, 0);
448 error = got_worktree_init(worktree_path, head_ref, path_prefix, repo);
449 if (error != NULL && !(error->code == GOT_ERR_ERRNO && errno == EEXIST))
452 error = got_worktree_open(&worktree, worktree_path);
456 error = got_worktree_match_path_prefix(&same_path_prefix, worktree,
460 if (!same_path_prefix) {
461 error = got_error(GOT_ERR_PATH_PREFIX);
466 struct got_object_id *commit_id;
467 error = got_object_resolve_id_str(&commit_id, repo,
471 error = check_linear_ancestry(worktree, commit_id, repo);
476 error = got_worktree_set_base_commit_id(worktree, repo,
483 error = got_worktree_checkout_files(worktree, "", repo,
484 checkout_progress, worktree_path, check_cancelled, NULL);
488 printf("Now shut up and hack\n");
500 fprintf(stderr, "usage: %s update [-c commit] [path]\n",
506 update_progress(void *arg, unsigned char status, const char *path)
508 int *did_something = arg;
510 if (status == GOT_STATUS_EXISTS)
514 while (path[0] == '/')
516 printf("%c %s\n", status, path);
519 static const struct got_error *
520 cmd_update(int argc, char *argv[])
522 const struct got_error *error = NULL;
523 struct got_repository *repo = NULL;
524 struct got_worktree *worktree = NULL;
525 char *worktree_path = NULL, *path = NULL;
526 struct got_object_id *commit_id = NULL;
527 char *commit_id_str = NULL;
528 int ch, did_something = 0;
530 while ((ch = getopt(argc, argv, "c:")) != -1) {
533 commit_id_str = strdup(optarg);
534 if (commit_id_str == NULL)
535 return got_error_from_errno("strdup");
547 if (pledge("stdio rpath wpath cpath fattr flock proc exec sendfd "
548 "unveil", NULL) == -1)
551 worktree_path = getcwd(NULL, 0);
552 if (worktree_path == NULL) {
553 error = got_error_from_errno("getcwd");
556 error = got_worktree_open(&worktree, worktree_path);
563 error = got_error_from_errno("strdup");
566 } else if (argc == 1) {
567 error = got_worktree_resolve_path(&path, worktree, argv[0]);
573 error = got_repo_open(&repo, got_worktree_get_repo_path(worktree));
577 error = apply_unveil(got_repo_get_path(repo), 0,
578 got_worktree_get_root_path(worktree), 0, 0);
582 if (commit_id_str == NULL) {
583 struct got_reference *head_ref;
584 error = got_ref_open(&head_ref, repo, GOT_REF_HEAD, 0);
587 error = got_ref_resolve(&commit_id, repo, head_ref);
590 error = got_object_id_str(&commit_id_str, commit_id);
594 error = got_object_resolve_id_str(&commit_id, repo,
600 error = check_linear_ancestry(worktree, commit_id, repo);
604 if (got_object_id_cmp(got_worktree_get_base_commit_id(worktree),
606 error = got_worktree_set_base_commit_id(worktree, repo,
612 error = got_worktree_checkout_files(worktree, path, repo,
613 update_progress, &did_something, check_cancelled, NULL);
618 printf("Updated to commit %s\n", commit_id_str);
620 printf("Already up-to-date\n");
629 static const struct got_error *
630 print_patch(struct got_commit_object *commit, struct got_object_id *id,
631 int diff_context, struct got_repository *repo)
633 const struct got_error *err = NULL;
634 struct got_tree_object *tree1 = NULL, *tree2;
635 struct got_object_qid *qid;
636 char *id_str1 = NULL, *id_str2;
638 err = got_object_open_as_tree(&tree2, repo,
639 got_object_commit_get_tree_id(commit));
643 qid = SIMPLEQ_FIRST(got_object_commit_get_parent_ids(commit));
645 struct got_commit_object *pcommit;
647 err = got_object_open_as_commit(&pcommit, repo, qid->id);
651 err = got_object_open_as_tree(&tree1, repo,
652 got_object_commit_get_tree_id(pcommit));
653 got_object_commit_close(pcommit);
657 err = got_object_id_str(&id_str1, qid->id);
662 err = got_object_id_str(&id_str2, id);
666 printf("diff %s %s\n", id_str1 ? id_str1 : "/dev/null", id_str2);
667 err = got_diff_tree(tree1, tree2, "", "", diff_context, repo, stdout);
670 got_object_tree_close(tree1);
671 got_object_tree_close(tree2);
678 get_datestr(time_t *time, char *datebuf)
680 char *p, *s = ctime_r(time, datebuf);
687 static const struct got_error *
688 print_commit(struct got_commit_object *commit, struct got_object_id *id,
689 struct got_repository *repo, int show_patch, int diff_context,
690 struct got_reflist_head *refs)
692 const struct got_error *err = NULL;
693 char *id_str, *datestr, *logmsg0, *logmsg, *line;
695 time_t committer_time;
696 const char *author, *committer;
697 char *refs_str = NULL;
698 struct got_reflist_entry *re;
700 SIMPLEQ_FOREACH(re, refs, entry) {
703 if (got_object_id_cmp(re->id, id) != 0)
705 name = got_ref_get_name(re->ref);
706 if (strcmp(name, GOT_REF_HEAD) == 0)
708 if (strncmp(name, "refs/", 5) == 0)
710 if (strncmp(name, "got/", 4) == 0)
712 if (strncmp(name, "heads/", 6) == 0)
714 if (strncmp(name, "remotes/", 8) == 0)
717 if (asprintf(&refs_str, "%s%s%s", s ? s : "", s ? ", " : "",
719 err = got_error_from_errno("asprintf");
725 err = got_object_id_str(&id_str, id);
729 printf("-----------------------------------------------\n");
730 printf("commit %s%s%s%s\n", id_str, refs_str ? " (" : "",
731 refs_str ? refs_str : "", refs_str ? ")" : "");
736 printf("from: %s\n", got_object_commit_get_author(commit));
737 committer_time = got_object_commit_get_committer_time(commit);
738 datestr = get_datestr(&committer_time, datebuf);
739 printf("date: %s UTC\n", datestr);
740 author = got_object_commit_get_author(commit);
741 committer = got_object_commit_get_committer(commit);
742 if (strcmp(author, committer) != 0)
743 printf("via: %s\n", committer);
744 if (got_object_commit_get_nparents(commit) > 1) {
745 const struct got_object_id_queue *parent_ids;
746 struct got_object_qid *qid;
748 parent_ids = got_object_commit_get_parent_ids(commit);
749 SIMPLEQ_FOREACH(qid, parent_ids, entry) {
750 err = got_object_id_str(&id_str, qid->id);
753 printf("parent %d: %s\n", n++, id_str);
758 logmsg0 = strdup(got_object_commit_get_logmsg(commit));
760 return got_error_from_errno("strdup");
764 line = strsep(&logmsg, "\n");
766 printf(" %s\n", line);
771 err = print_patch(commit, id, diff_context, repo);
776 if (fflush(stdout) != 0 && err == NULL)
777 err = got_error_from_errno("fflush");
781 static const struct got_error *
782 print_commits(struct got_object_id *root_id, struct got_repository *repo,
783 char *path, int show_patch, int diff_context, int limit,
784 int first_parent_traversal, struct got_reflist_head *refs)
786 const struct got_error *err;
787 struct got_commit_graph *graph;
789 err = got_commit_graph_open(&graph, root_id, path,
790 first_parent_traversal, repo);
793 err = got_commit_graph_iter_start(graph, root_id, repo);
797 struct got_commit_object *commit;
798 struct got_object_id *id;
800 if (sigint_received || sigpipe_received)
803 err = got_commit_graph_iter_next(&id, graph);
805 if (err->code == GOT_ERR_ITER_COMPLETED) {
809 if (err->code != GOT_ERR_ITER_NEED_MORE)
811 err = got_commit_graph_fetch_commits(graph, 1, repo);
820 err = got_object_open_as_commit(&commit, repo, id);
823 err = print_commit(commit, id, repo, show_patch, diff_context,
825 got_object_commit_close(commit);
826 if (err || (limit && --limit == 0))
830 got_commit_graph_close(graph);
837 fprintf(stderr, "usage: %s log [-c commit] [-C number] [-f] [ -l N ] [-p] "
838 "[-r repository-path] [path]\n", getprogname());
842 static const struct got_error *
843 cmd_log(int argc, char *argv[])
845 const struct got_error *error;
846 struct got_repository *repo = NULL;
847 struct got_worktree *worktree = NULL;
848 struct got_commit_object *commit = NULL;
849 struct got_object_id *id = NULL;
850 char *repo_path = NULL, *path = NULL, *cwd = NULL, *in_repo_path = NULL;
851 char *start_commit = NULL;
852 int diff_context = 3, ch;
853 int show_patch = 0, limit = 0, first_parent_traversal = 0;
855 struct got_reflist_head refs;
860 if (pledge("stdio rpath wpath cpath flock proc exec sendfd unveil",
866 while ((ch = getopt(argc, argv, "pc:C:l:fr:")) != -1) {
872 start_commit = optarg;
875 diff_context = strtonum(optarg, 0, GOT_DIFF_MAX_CONTEXT,
878 err(1, "-C option %s", errstr);
881 limit = strtonum(optarg, 1, INT_MAX, &errstr);
883 err(1, "-l option %s", errstr);
886 first_parent_traversal = 1;
889 repo_path = realpath(optarg, NULL);
890 if (repo_path == NULL)
892 got_path_strip_trailing_slashes(repo_path);
903 cwd = getcwd(NULL, 0);
905 error = got_error_from_errno("getcwd");
909 error = got_worktree_open(&worktree, cwd);
910 if (error && error->code != GOT_ERR_NOT_WORKTREE)
917 error = got_error_from_errno("strdup");
920 } else if (argc == 1) {
922 error = got_worktree_resolve_path(&path, worktree,
927 path = strdup(argv[0]);
929 error = got_error_from_errno("strdup");
936 if (repo_path == NULL) {
937 repo_path = worktree ?
938 strdup(got_worktree_get_repo_path(worktree)) : strdup(cwd);
940 if (repo_path == NULL) {
941 error = got_error_from_errno("strdup");
945 error = got_repo_open(&repo, repo_path);
949 error = apply_unveil(got_repo_get_path(repo), 1,
950 worktree ? got_worktree_get_root_path(worktree) : NULL, 0, 0);
954 if (start_commit == NULL) {
955 struct got_reference *head_ref;
956 error = got_ref_open(&head_ref, repo, GOT_REF_HEAD, 0);
959 error = got_ref_resolve(&id, repo, head_ref);
960 got_ref_close(head_ref);
963 error = got_object_open_as_commit(&commit, repo, id);
965 struct got_reference *ref;
966 error = got_ref_open(&ref, repo, start_commit, 0);
969 error = got_ref_resolve(&id, repo, ref);
973 error = got_object_get_type(&obj_type, repo, id);
976 if (obj_type == GOT_OBJ_TYPE_TAG) {
977 struct got_tag_object *tag;
978 error = got_object_open_as_tag(&tag, repo, id);
981 if (got_object_tag_get_object_type(tag) !=
982 GOT_OBJ_TYPE_COMMIT) {
983 got_object_tag_close(tag);
984 error = got_error(GOT_ERR_OBJ_TYPE);
988 id = got_object_id_dup(
989 got_object_tag_get_object_id(tag));
991 error = got_error_from_errno(
992 "got_object_id_dup");
993 got_object_tag_close(tag);
996 } else if (obj_type != GOT_OBJ_TYPE_COMMIT) {
997 error = got_error(GOT_ERR_OBJ_TYPE);
1000 error = got_object_open_as_commit(&commit, repo, id);
1004 if (commit == NULL) {
1005 error = got_object_resolve_id_str(&id, repo,
1014 error = got_repo_map_path(&in_repo_path, repo, path, 1);
1019 path = in_repo_path;
1022 error = got_ref_list(&refs, repo);
1026 error = print_commits(id, repo, path, show_patch,
1027 diff_context, limit, first_parent_traversal, &refs);
1034 got_worktree_close(worktree);
1036 const struct got_error *repo_error;
1037 repo_error = got_repo_close(repo);
1041 got_ref_list_free(&refs);
1048 fprintf(stderr, "usage: %s diff [-C number] [-r repository-path] "
1049 "[object1 object2 | path]\n", getprogname());
1053 struct print_diff_arg {
1054 struct got_repository *repo;
1055 struct got_worktree *worktree;
1061 static const struct got_error *
1062 print_diff(void *arg, unsigned char status, const char *path,
1063 struct got_object_id *id)
1065 struct print_diff_arg *a = arg;
1066 const struct got_error *err = NULL;
1067 struct got_blob_object *blob1 = NULL;
1069 char *abspath = NULL;
1072 if (status != GOT_STATUS_MODIFY && status != GOT_STATUS_ADD &&
1073 status != GOT_STATUS_DELETE && status != GOT_STATUS_CONFLICT)
1076 if (!a->header_shown) {
1077 printf("diff %s %s\n", a->id_str,
1078 got_worktree_get_root_path(a->worktree));
1079 a->header_shown = 1;
1082 if (status != GOT_STATUS_ADD) {
1083 err = got_object_open_as_blob(&blob1, a->repo, id, 8192);
1089 if (status != GOT_STATUS_DELETE) {
1090 if (asprintf(&abspath, "%s/%s",
1091 got_worktree_get_root_path(a->worktree), path) == -1) {
1092 err = got_error_from_errno("asprintf");
1096 f2 = fopen(abspath, "r");
1098 err = got_error_from_errno2("fopen", abspath);
1101 if (lstat(abspath, &sb) == -1) {
1102 err = got_error_from_errno2("lstat", abspath);
1108 err = got_diff_blob_file(blob1, f2, sb.st_size, path, a->diff_context,
1112 got_object_blob_close(blob1);
1113 if (f2 && fclose(f2) != 0 && err == NULL)
1114 err = got_error_from_errno("fclose");
1119 static const struct got_error *
1120 cmd_diff(int argc, char *argv[])
1122 const struct got_error *error;
1123 struct got_repository *repo = NULL;
1124 struct got_worktree *worktree = NULL;
1125 char *cwd = NULL, *repo_path = NULL;
1126 struct got_object_id *id1 = NULL, *id2 = NULL;
1127 char *id_str1 = NULL, *id_str2 = NULL;
1129 int diff_context = 3, ch;
1134 if (pledge("stdio rpath wpath cpath flock proc exec sendfd unveil",
1139 while ((ch = getopt(argc, argv, "C:r:")) != -1) {
1142 diff_context = strtonum(optarg, 1, INT_MAX, &errstr);
1144 err(1, "-C option %s", errstr);
1147 repo_path = realpath(optarg, NULL);
1148 if (repo_path == NULL)
1149 err(1, "-r option");
1150 got_path_strip_trailing_slashes(repo_path);
1161 cwd = getcwd(NULL, 0);
1163 error = got_error_from_errno("getcwd");
1166 error = got_worktree_open(&worktree, cwd);
1167 if (error && error->code != GOT_ERR_NOT_WORKTREE)
1170 if (worktree == NULL) {
1171 error = got_error(GOT_ERR_NOT_WORKTREE);
1176 "-r option can't be used when diffing a work tree");
1177 repo_path = strdup(got_worktree_get_repo_path(worktree));
1178 if (repo_path == NULL) {
1179 error = got_error_from_errno("strdup");
1183 error = got_worktree_resolve_path(&path, worktree,
1190 error = got_error_from_errno("strdup");
1194 } else if (argc == 2) {
1200 if (repo_path == NULL) {
1201 repo_path = getcwd(NULL, 0);
1202 if (repo_path == NULL)
1203 return got_error_from_errno("getcwd");
1206 error = got_repo_open(&repo, repo_path);
1211 error = apply_unveil(got_repo_get_path(repo), 1,
1212 worktree ? got_worktree_get_root_path(worktree) : NULL, 0, 0);
1217 struct print_diff_arg arg;
1219 error = got_object_id_str(&id_str,
1220 got_worktree_get_base_commit_id(worktree));
1224 arg.worktree = worktree;
1225 arg.diff_context = diff_context;
1226 arg.id_str = id_str;
1227 arg.header_shown = 0;
1229 error = got_worktree_status(worktree, path, repo, print_diff,
1230 &arg, check_cancelled, NULL);
1235 error = got_object_resolve_id_str(&id1, repo, id_str1);
1239 error = got_object_resolve_id_str(&id2, repo, id_str2);
1243 error = got_object_get_type(&type1, repo, id1);
1247 error = got_object_get_type(&type2, repo, id2);
1251 if (type1 != type2) {
1252 error = got_error(GOT_ERR_OBJ_TYPE);
1257 case GOT_OBJ_TYPE_BLOB:
1258 error = got_diff_objects_as_blobs(id1, id2, NULL, NULL,
1259 diff_context, repo, stdout);
1261 case GOT_OBJ_TYPE_TREE:
1262 error = got_diff_objects_as_trees(id1, id2, "", "",
1263 diff_context, repo, stdout);
1265 case GOT_OBJ_TYPE_COMMIT:
1266 printf("diff %s %s\n", id_str1 ? id_str1 : "/dev/null",
1268 error = got_diff_objects_as_commits(id1, id2, diff_context,
1272 error = got_error(GOT_ERR_OBJ_TYPE);
1280 got_worktree_close(worktree);
1282 const struct got_error *repo_error;
1283 repo_error = got_repo_close(repo);
1294 "usage: %s blame [-c commit] [-r repository-path] path\n",
1299 static const struct got_error *
1300 cmd_blame(int argc, char *argv[])
1302 const struct got_error *error;
1303 struct got_repository *repo = NULL;
1304 struct got_worktree *worktree = NULL;
1305 char *path, *cwd = NULL, *repo_path = NULL, *in_repo_path = NULL;
1306 struct got_object_id *commit_id = NULL;
1307 char *commit_id_str = NULL;
1311 if (pledge("stdio rpath wpath cpath flock proc exec sendfd unveil",
1316 while ((ch = getopt(argc, argv, "c:r:")) != -1) {
1319 commit_id_str = optarg;
1322 repo_path = realpath(optarg, NULL);
1323 if (repo_path == NULL)
1324 err(1, "-r option");
1325 got_path_strip_trailing_slashes(repo_path);
1341 cwd = getcwd(NULL, 0);
1343 error = got_error_from_errno("getcwd");
1346 if (repo_path == NULL) {
1347 error = got_worktree_open(&worktree, cwd);
1348 if (error && error->code != GOT_ERR_NOT_WORKTREE)
1354 strdup(got_worktree_get_repo_path(worktree));
1355 if (repo_path == NULL)
1356 error = got_error_from_errno("strdup");
1360 repo_path = strdup(cwd);
1361 if (repo_path == NULL) {
1362 error = got_error_from_errno("strdup");
1368 error = got_repo_open(&repo, repo_path);
1372 error = apply_unveil(got_repo_get_path(repo), 1, NULL, 0, 0);
1377 const char *prefix = got_worktree_get_path_prefix(worktree);
1378 char *p, *worktree_subdir = cwd +
1379 strlen(got_worktree_get_root_path(worktree));
1380 if (asprintf(&p, "%s%s%s%s%s",
1381 prefix, (strcmp(prefix, "/") != 0) ? "/" : "",
1382 worktree_subdir, worktree_subdir[0] ? "/" : "",
1384 error = got_error_from_errno("asprintf");
1387 error = got_repo_map_path(&in_repo_path, repo, p, 0);
1390 error = got_repo_map_path(&in_repo_path, repo, path, 1);
1395 if (commit_id_str == NULL) {
1396 struct got_reference *head_ref;
1397 error = got_ref_open(&head_ref, repo, GOT_REF_HEAD, 0);
1400 error = got_ref_resolve(&commit_id, repo, head_ref);
1401 got_ref_close(head_ref);
1405 error = got_object_resolve_id_str(&commit_id, repo,
1411 error = got_blame(in_repo_path, commit_id, repo, stdout);
1418 got_worktree_close(worktree);
1420 const struct got_error *repo_error;
1421 repo_error = got_repo_close(repo);
1432 "usage: %s tree [-c commit] [-r repository-path] [-iR] path\n",
1438 print_entry(struct got_tree_entry *te, const char *id, const char *path,
1439 const char *root_path)
1441 int is_root_path = (strcmp(path, root_path) == 0);
1443 path += strlen(root_path);
1444 while (path[0] == '/')
1447 printf("%s%s%s%s%s\n", id ? id : "", path,
1448 is_root_path ? "" : "/", te->name,
1449 S_ISDIR(te->mode) ? "/" : ((te->mode & S_IXUSR) ? "*" : ""));
1452 static const struct got_error *
1453 print_tree(const char *path, struct got_object_id *commit_id,
1454 int show_ids, int recurse, const char *root_path,
1455 struct got_repository *repo)
1457 const struct got_error *err = NULL;
1458 struct got_object_id *tree_id = NULL;
1459 struct got_tree_object *tree = NULL;
1460 const struct got_tree_entries *entries;
1461 struct got_tree_entry *te;
1463 err = got_object_id_by_path(&tree_id, repo, commit_id, path);
1467 err = got_object_open_as_tree(&tree, repo, tree_id);
1470 entries = got_object_tree_get_entries(tree);
1471 te = SIMPLEQ_FIRST(&entries->head);
1475 if (sigint_received || sigpipe_received)
1480 err = got_object_id_str(&id_str, te->id);
1483 if (asprintf(&id, "%s ", id_str) == -1) {
1484 err = got_error_from_errno("asprintf");
1490 print_entry(te, id, path, root_path);
1493 if (recurse && S_ISDIR(te->mode)) {
1495 if (asprintf(&child_path, "%s%s%s", path,
1496 path[0] == '/' && path[1] == '\0' ? "" : "/",
1498 err = got_error_from_errno("asprintf");
1501 err = print_tree(child_path, commit_id, show_ids, 1,
1508 te = SIMPLEQ_NEXT(te, entry);
1512 got_object_tree_close(tree);
1517 static const struct got_error *
1518 cmd_tree(int argc, char *argv[])
1520 const struct got_error *error;
1521 struct got_repository *repo = NULL;
1522 struct got_worktree *worktree = NULL;
1524 char *cwd = NULL, *repo_path = NULL, *in_repo_path = NULL;
1525 struct got_object_id *commit_id = NULL;
1526 char *commit_id_str = NULL;
1527 int show_ids = 0, recurse = 0;
1531 if (pledge("stdio rpath wpath cpath flock proc exec sendfd unveil",
1536 while ((ch = getopt(argc, argv, "c:r:iR")) != -1) {
1539 commit_id_str = optarg;
1542 repo_path = realpath(optarg, NULL);
1543 if (repo_path == NULL)
1544 err(1, "-r option");
1545 got_path_strip_trailing_slashes(repo_path);
1569 cwd = getcwd(NULL, 0);
1571 error = got_error_from_errno("getcwd");
1574 if (repo_path == NULL) {
1575 error = got_worktree_open(&worktree, cwd);
1576 if (error && error->code != GOT_ERR_NOT_WORKTREE)
1582 strdup(got_worktree_get_repo_path(worktree));
1583 if (repo_path == NULL)
1584 error = got_error_from_errno("strdup");
1588 repo_path = strdup(cwd);
1589 if (repo_path == NULL) {
1590 error = got_error_from_errno("strdup");
1596 error = got_repo_open(&repo, repo_path);
1600 error = apply_unveil(got_repo_get_path(repo), 1, NULL, 0, 0);
1606 char *p, *worktree_subdir = cwd +
1607 strlen(got_worktree_get_root_path(worktree));
1608 if (asprintf(&p, "%s/%s",
1609 got_worktree_get_path_prefix(worktree),
1610 worktree_subdir) == -1) {
1611 error = got_error_from_errno("asprintf");
1614 error = got_repo_map_path(&in_repo_path, repo, p, 1);
1621 if (in_repo_path == NULL) {
1622 error = got_repo_map_path(&in_repo_path, repo, path, 1);
1627 if (commit_id_str == NULL) {
1628 struct got_reference *head_ref;
1629 error = got_ref_open(&head_ref, repo, GOT_REF_HEAD, 0);
1632 error = got_ref_resolve(&commit_id, repo, head_ref);
1633 got_ref_close(head_ref);
1637 error = got_object_resolve_id_str(&commit_id, repo,
1643 error = print_tree(in_repo_path, commit_id, show_ids, recurse,
1644 in_repo_path, repo);
1651 got_worktree_close(worktree);
1653 const struct got_error *repo_error;
1654 repo_error = got_repo_close(repo);
1664 fprintf(stderr, "usage: %s status [path]\n", getprogname());
1668 static const struct got_error *
1669 print_status(void *arg, unsigned char status, const char *path,
1670 struct got_object_id *id)
1672 printf("%c %s\n", status, path);
1676 static const struct got_error *
1677 cmd_status(int argc, char *argv[])
1679 const struct got_error *error = NULL;
1680 struct got_repository *repo = NULL;
1681 struct got_worktree *worktree = NULL;
1682 char *cwd = NULL, *path = NULL;
1685 while ((ch = getopt(argc, argv, "")) != -1) {
1697 if (pledge("stdio rpath wpath cpath flock proc exec sendfd unveil",
1701 cwd = getcwd(NULL, 0);
1703 error = got_error_from_errno("getcwd");
1707 error = got_worktree_open(&worktree, cwd);
1714 error = got_error_from_errno("strdup");
1717 } else if (argc == 1) {
1718 error = got_worktree_resolve_path(&path, worktree, argv[0]);
1724 error = got_repo_open(&repo, got_worktree_get_repo_path(worktree));
1728 error = apply_unveil(got_repo_get_path(repo), 1,
1729 got_worktree_get_root_path(worktree), 0, 0);
1733 error = got_worktree_status(worktree, path, repo, print_status, NULL,
1734 check_cancelled, NULL);
1745 "usage: %s ref [-r repository] -l | -d name | name object\n",
1750 static const struct got_error *
1751 list_refs(struct got_repository *repo)
1753 static const struct got_error *err = NULL;
1754 struct got_reflist_head refs;
1755 struct got_reflist_entry *re;
1757 SIMPLEQ_INIT(&refs);
1758 err = got_ref_list(&refs, repo);
1762 SIMPLEQ_FOREACH(re, &refs, entry) {
1764 refstr = got_ref_to_str(re->ref);
1766 return got_error_from_errno("got_ref_to_str");
1767 printf("%s: %s\n", got_ref_get_name(re->ref), refstr);
1771 got_ref_list_free(&refs);
1775 static const struct got_error *
1776 delete_ref(struct got_repository *repo, const char *refname)
1778 const struct got_error *err = NULL;
1779 struct got_reference *ref;
1781 err = got_ref_open(&ref, repo, refname, 0);
1785 err = got_ref_delete(ref, repo);
1790 static const struct got_error *
1791 add_ref(struct got_repository *repo, const char *refname, const char *id_str)
1793 const struct got_error *err = NULL;
1794 struct got_object_id *id;
1795 struct got_reference *ref = NULL;
1797 err = got_object_resolve_id_str(&id, repo, id_str);
1801 err = got_ref_alloc(&ref, refname, id);
1805 err = got_ref_write(ref, repo);
1813 static const struct got_error *
1814 cmd_ref(int argc, char *argv[])
1816 const struct got_error *error = NULL;
1817 struct got_repository *repo = NULL;
1818 struct got_worktree *worktree = NULL;
1819 char *cwd = NULL, *repo_path = NULL;
1820 int ch, do_list = 0;
1821 const char *delref = NULL;
1823 /* TODO: Add -s option for adding symbolic references. */
1824 while ((ch = getopt(argc, argv, "d:r:l")) != -1) {
1830 repo_path = realpath(optarg, NULL);
1831 if (repo_path == NULL)
1832 err(1, "-r option");
1833 got_path_strip_trailing_slashes(repo_path);
1844 if (do_list && delref)
1845 errx(1, "-l and -d options are mutually exclusive\n");
1850 if (do_list || delref) {
1853 } else if (argc != 2)
1858 if (pledge("stdio rpath wpath flock proc exec sendfd unveil",
1862 if (pledge("stdio rpath wpath cpath fattr flock proc exec "
1863 "sendfd unveil", NULL) == -1)
1867 cwd = getcwd(NULL, 0);
1869 error = got_error_from_errno("getcwd");
1873 if (repo_path == NULL) {
1874 error = got_worktree_open(&worktree, cwd);
1875 if (error && error->code != GOT_ERR_NOT_WORKTREE)
1881 strdup(got_worktree_get_repo_path(worktree));
1882 if (repo_path == NULL)
1883 error = got_error_from_errno("strdup");
1887 repo_path = strdup(cwd);
1888 if (repo_path == NULL) {
1889 error = got_error_from_errno("strdup");
1895 error = got_repo_open(&repo, repo_path);
1899 error = apply_unveil(got_repo_get_path(repo), do_list,
1900 worktree ? got_worktree_get_root_path(worktree) : NULL, 0, 0);
1905 error = list_refs(repo);
1907 error = delete_ref(repo, delref);
1909 error = add_ref(repo, argv[0], argv[1]);
1912 got_repo_close(repo);
1914 got_worktree_close(worktree);
1923 fprintf(stderr, "usage: %s add file-path ...\n", getprogname());
1927 static const struct got_error *
1928 cmd_add(int argc, char *argv[])
1930 const struct got_error *error = NULL;
1931 struct got_repository *repo = NULL;
1932 struct got_worktree *worktree = NULL;
1934 struct got_pathlist_head paths;
1935 struct got_pathlist_entry *pe;
1940 while ((ch = getopt(argc, argv, "")) != -1) {
1954 /* make sure each file exists before doing anything halfway */
1955 for (x = 0; x < argc; x++) {
1956 char *path = realpath(argv[x], NULL);
1958 error = got_error_from_errno2("realpath", argv[x]);
1964 cwd = getcwd(NULL, 0);
1966 error = got_error_from_errno("getcwd");
1970 error = got_worktree_open(&worktree, cwd);
1974 error = got_repo_open(&repo, got_worktree_get_repo_path(worktree));
1978 error = apply_unveil(got_repo_get_path(repo), 1,
1979 got_worktree_get_root_path(worktree), 0, 0);
1983 for (x = 0; x < argc; x++) {
1984 char *path = realpath(argv[x], NULL);
1986 error = got_error_from_errno2("realpath", argv[x]);
1990 got_path_strip_trailing_slashes(path);
1991 error = got_pathlist_insert(&pe, &paths, path, NULL);
1997 error = got_worktree_schedule_add(worktree, &paths, print_status,
2001 got_repo_close(repo);
2003 got_worktree_close(worktree);
2004 TAILQ_FOREACH(pe, &paths, entry)
2005 free((char *)pe->path);
2006 got_pathlist_free(&paths);
2014 fprintf(stderr, "usage: %s rm [-f] file-path\n", getprogname());
2018 static const struct got_error *
2019 cmd_rm(int argc, char *argv[])
2021 const struct got_error *error = NULL;
2022 struct got_worktree *worktree = NULL;
2023 struct got_repository *repo = NULL;
2024 char *cwd = NULL, *path = NULL;
2025 int ch, delete_local_mods = 0;
2027 while ((ch = getopt(argc, argv, "f")) != -1) {
2030 delete_local_mods = 1;
2044 path = realpath(argv[0], NULL);
2046 error = got_error_from_errno2("realpath", argv[0]);
2049 got_path_strip_trailing_slashes(path);
2051 cwd = getcwd(NULL, 0);
2053 error = got_error_from_errno("getcwd");
2056 error = got_worktree_open(&worktree, cwd);
2060 error = got_repo_open(&repo, got_worktree_get_repo_path(worktree));
2064 error = apply_unveil(got_repo_get_path(repo), 1,
2065 got_worktree_get_root_path(worktree), 0, 0);
2069 error = got_worktree_schedule_delete(worktree, path, delete_local_mods,
2070 print_status, NULL, repo);
2075 got_repo_close(repo);
2077 got_worktree_close(worktree);
2086 fprintf(stderr, "usage: %s revert file-path\n", getprogname());
2091 revert_progress(void *arg, unsigned char status, const char *path)
2093 while (path[0] == '/')
2095 printf("%c %s\n", status, path);
2098 static const struct got_error *
2099 cmd_revert(int argc, char *argv[])
2101 const struct got_error *error = NULL;
2102 struct got_worktree *worktree = NULL;
2103 struct got_repository *repo = NULL;
2104 char *cwd = NULL, *path = NULL;
2107 while ((ch = getopt(argc, argv, "")) != -1) {
2121 path = realpath(argv[0], NULL);
2123 error = got_error_from_errno2("realpath", argv[0]);
2126 got_path_strip_trailing_slashes(path);
2128 cwd = getcwd(NULL, 0);
2130 error = got_error_from_errno("getcwd");
2133 error = got_worktree_open(&worktree, cwd);
2137 error = got_repo_open(&repo, got_worktree_get_repo_path(worktree));
2141 error = apply_unveil(got_repo_get_path(repo), 1,
2142 got_worktree_get_root_path(worktree), 0, 0);
2146 error = got_worktree_revert(worktree, path,
2147 revert_progress, NULL, repo);
2152 got_repo_close(repo);
2154 got_worktree_close(worktree);
2163 fprintf(stderr, "usage: %s commit [-m msg] file-path\n", getprogname());
2168 spawn_editor(const char *editor, const char *file)
2171 sig_t sighup, sigint, sigquit;
2174 sighup = signal(SIGHUP, SIG_IGN);
2175 sigint = signal(SIGINT, SIG_IGN);
2176 sigquit = signal(SIGQUIT, SIG_IGN);
2178 switch (pid = fork()) {
2182 execl(editor, editor, file, (char *)NULL);
2186 while (waitpid(pid, &st, 0) == -1)
2191 (void)signal(SIGHUP, sighup);
2192 (void)signal(SIGINT, sigint);
2193 (void)signal(SIGQUIT, sigquit);
2195 if (!WIFEXITED(st)) {
2200 return WEXITSTATUS(st);
2203 struct collect_commit_logmsg_arg {
2204 const char *cmdline_log;
2206 const char *worktree_path;
2211 static const struct got_error *
2212 collect_commit_logmsg(struct got_pathlist_head *commitable_paths, char **logmsg,
2215 const char *initial_content = "\n# changes to be committed:\n";
2216 struct got_pathlist_entry *pe;
2217 const struct got_error *err = NULL;
2218 char *template = NULL;
2219 struct collect_commit_logmsg_arg *a = arg;
2221 struct stat st, st2;
2224 int fd, content_changed = 0;
2226 /* if a message was specified on the command line, just use it */
2227 if (a->cmdline_log != NULL && strlen(a->cmdline_log) != 0) {
2228 len = strlen(a->cmdline_log) + 1;
2229 *logmsg = malloc(len + 1);
2230 if (*logmsg == NULL)
2231 return got_error_from_errno("malloc");
2232 strlcpy(*logmsg, a->cmdline_log, len);
2236 if (asprintf(&template, "%s/logmsg", a->worktree_path) == -1)
2237 return got_error_from_errno("asprintf");
2239 err = got_opentemp_named_fd(&a->logmsg_path, &fd, template);
2243 dprintf(fd, initial_content);
2245 TAILQ_FOREACH(pe, commitable_paths, entry) {
2246 struct got_commitable *ct = pe->data;
2247 dprintf(fd, "# %c %s\n", ct->status, pe->path);
2251 if (stat(a->logmsg_path, &st) == -1) {
2252 err = got_error_from_errno2("stat", a->logmsg_path);
2256 if (spawn_editor(a->editor, a->logmsg_path) == -1) {
2257 err = got_error_from_errno("failed spawning editor");
2261 if (stat(a->logmsg_path, &st2) == -1) {
2262 err = got_error_from_errno("stat");
2266 if (st.st_mtime == st2.st_mtime && st.st_size == st2.st_size) {
2267 unlink(a->logmsg_path);
2268 free(a->logmsg_path);
2269 a->logmsg_path = NULL;
2270 err = got_error_msg(GOT_ERR_COMMIT_MSG_EMPTY,
2271 "no changes made to commit message, aborting");
2275 /* remove comments */
2276 *logmsg = malloc(st2.st_size + 1);
2277 if (*logmsg == NULL) {
2278 err = got_error_from_errno("malloc");
2283 fp = fopen(a->logmsg_path, "r");
2284 while (fgets(buf, sizeof(buf), fp) != NULL) {
2285 if (!content_changed && strcmp(buf, initial_content) != 0)
2286 content_changed = 1;
2287 if (buf[0] == '#' || (len == 0 && buf[0] == '\n'))
2289 len = strlcat(*logmsg, buf, st2.st_size);
2293 while (len > 0 && (*logmsg)[len - 1] == '\n') {
2294 (*logmsg)[len - 1] = '\0';
2298 if (len == 0 || !content_changed) {
2299 unlink(a->logmsg_path);
2300 free(a->logmsg_path);
2301 a->logmsg_path = NULL;
2302 err = got_error_msg(GOT_ERR_COMMIT_MSG_EMPTY,
2303 "commit message cannot be empty, aborting");
2311 static const struct got_error *
2312 cmd_commit(int argc, char *argv[])
2314 const struct got_error *error = NULL;
2315 struct got_worktree *worktree = NULL;
2316 struct got_repository *repo = NULL;
2317 char *cwd = NULL, *path = NULL, *id_str = NULL;
2318 struct got_object_id *id = NULL;
2319 const char *logmsg = NULL;
2320 const char *got_author = getenv("GOT_AUTHOR");
2321 struct collect_commit_logmsg_arg cl_arg;
2322 char *editor = NULL;
2325 while ((ch = getopt(argc, argv, "m:")) != -1) {
2340 path = realpath(argv[0], NULL);
2342 error = got_error_from_errno2("realpath", argv[0]);
2345 got_path_strip_trailing_slashes(path);
2346 } else if (argc != 0)
2349 if (got_author == NULL) {
2350 /* TODO: Look current user up in password database */
2351 error = got_error(GOT_ERR_COMMIT_NO_AUTHOR);
2355 cwd = getcwd(NULL, 0);
2357 error = got_error_from_errno("getcwd");
2360 error = got_worktree_open(&worktree, cwd);
2364 error = got_repo_open(&repo, got_worktree_get_repo_path(worktree));
2368 error = apply_unveil(got_repo_get_path(repo), 0,
2369 got_worktree_get_root_path(worktree), 0, 1);
2373 error = get_editor(&editor);
2376 cl_arg.editor = editor;
2377 cl_arg.cmdline_log = logmsg;
2378 cl_arg.worktree_path = got_worktree_get_root_path(worktree);
2379 cl_arg.logmsg_path = NULL;
2380 error = got_worktree_commit(&id, worktree, path, got_author, NULL,
2381 collect_commit_logmsg, &cl_arg, print_status, NULL, repo);
2383 if (cl_arg.logmsg_path)
2384 fprintf(stderr, "%s: log message preserved in %s\n",
2385 getprogname(), cl_arg.logmsg_path);
2389 if (cl_arg.logmsg_path)
2390 unlink(cl_arg.logmsg_path);
2392 error = got_object_id_str(&id_str, id);
2395 printf("created commit %s\n", id_str);
2398 got_repo_close(repo);
2400 got_worktree_close(worktree);