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 **abspath)
202 const struct got_error *err = NULL;
205 editor = getenv("VISUAL");
207 editor = getenv("EDITOR");
210 err = got_path_find_prog(abspath, editor);
215 if (*abspath == NULL) {
216 *abspath = strdup("/bin/ed");
217 if (*abspath == NULL)
218 return got_error_from_errno("strdup");
224 static const struct got_error *
225 apply_unveil(const char *repo_path, int repo_read_only,
226 const char *worktree_path, int create_worktree, char **editor)
228 const struct got_error *err;
229 static char err_msg[MAXPATHLEN + 36];
231 if (create_worktree) {
232 /* Pre-create work tree path to avoid unveiling its parents. */
233 err = got_path_mkdir(worktree_path);
235 if (errno == EEXIST) {
236 if (got_path_dir_is_empty(worktree_path)) {
240 snprintf(err_msg, sizeof(err_msg),
241 "%s: directory exists but is not empty",
243 err = got_error_msg(GOT_ERR_BAD_PATH,
248 if (err && (err->code != GOT_ERR_ERRNO || errno != EISDIR))
253 err = get_editor(editor);
256 if (unveil(*editor, "x") != 0) {
257 err = got_error_from_errno2("unveil", *editor);
264 if (repo_path && unveil(repo_path, repo_read_only ? "r" : "rwc") != 0)
265 return got_error_from_errno2("unveil", repo_path);
267 if (worktree_path && unveil(worktree_path, "rwc") != 0)
268 return got_error_from_errno2("unveil", worktree_path);
270 if (unveil("/tmp", "rwc") != 0)
271 return got_error_from_errno2("unveil", "/tmp");
273 err = got_privsep_unveil_exec_helpers();
277 if (unveil(NULL, NULL) != 0)
278 return got_error_from_errno("unveil");
286 fprintf(stderr, "usage: %s checkout [-p prefix] repository-path "
287 "[worktree-path]\n", getprogname());
292 checkout_progress(void *arg, unsigned char status, const char *path)
294 char *worktree_path = arg;
296 while (path[0] == '/')
299 printf("%c %s/%s\n", status, worktree_path, path);
302 static const struct got_error *
303 check_cancelled(void *arg)
305 if (sigint_received || sigpipe_received)
306 return got_error(GOT_ERR_CANCELLED);
310 static const struct got_error *
311 check_linear_ancestry(struct got_worktree *worktree,
312 struct got_object_id *commit_id, struct got_repository *repo)
314 const struct got_error *err = NULL;
315 struct got_object_id *yca_id, *base_commit_id;
317 base_commit_id = got_worktree_get_base_commit_id(worktree);
318 err = got_commit_graph_find_youngest_common_ancestor(&yca_id,
319 commit_id, base_commit_id, repo);
324 return got_error(GOT_ERR_ANCESTRY);
327 * Require a straight line of history between the target commit
328 * and the work tree's base commit.
330 * Non-linear situation such as the this require a rebase:
332 * (commit) D F (base_commit)
340 * 'got update' only handles linear cases:
341 * Update forwards in time: A (base/yca) - B - C - D (commit)
342 * Update backwards in time: D (base) - C - D - A (commit/yca)
344 if (got_object_id_cmp(commit_id, yca_id) != 0 &&
345 got_object_id_cmp(base_commit_id, yca_id) != 0)
346 return got_error(GOT_ERR_ANCESTRY);
353 static const struct got_error *
354 cmd_checkout(int argc, char *argv[])
356 const struct got_error *error = NULL;
357 struct got_repository *repo = NULL;
358 struct got_reference *head_ref = NULL;
359 struct got_worktree *worktree = NULL;
360 char *repo_path = NULL;
361 char *worktree_path = NULL;
362 const char *path_prefix = "";
363 char *commit_id_str = NULL;
364 int ch, same_path_prefix;
366 while ((ch = getopt(argc, argv, "c:p:")) != -1) {
369 commit_id_str = strdup(optarg);
370 if (commit_id_str == NULL)
371 return got_error_from_errno("strdup");
374 path_prefix = optarg;
386 if (pledge("stdio rpath wpath cpath fattr flock proc exec sendfd "
387 "unveil", NULL) == -1)
391 char *cwd, *base, *dotgit;
392 repo_path = realpath(argv[0], NULL);
393 if (repo_path == NULL)
394 return got_error_from_errno2("realpath", argv[0]);
395 cwd = getcwd(NULL, 0);
397 error = got_error_from_errno("getcwd");
400 if (path_prefix[0]) {
401 base = basename(path_prefix);
403 error = got_error_from_errno2("basename",
408 base = basename(repo_path);
410 error = got_error_from_errno2("basename",
415 dotgit = strstr(base, ".git");
418 if (asprintf(&worktree_path, "%s/%s", cwd, base) == -1) {
419 error = got_error_from_errno("asprintf");
424 } else if (argc == 2) {
425 repo_path = realpath(argv[0], NULL);
426 if (repo_path == NULL) {
427 error = got_error_from_errno2("realpath", argv[0]);
430 worktree_path = realpath(argv[1], NULL);
431 if (worktree_path == NULL) {
432 error = got_error_from_errno2("realpath", argv[1]);
438 got_path_strip_trailing_slashes(repo_path);
439 got_path_strip_trailing_slashes(worktree_path);
441 error = got_repo_open(&repo, repo_path);
445 error = apply_unveil(got_repo_get_path(repo), 0, worktree_path, 1,
450 error = got_ref_open(&head_ref, repo, GOT_REF_HEAD, 0);
454 error = got_worktree_init(worktree_path, head_ref, path_prefix, repo);
455 if (error != NULL && !(error->code == GOT_ERR_ERRNO && errno == EEXIST))
458 error = got_worktree_open(&worktree, worktree_path);
462 error = got_worktree_match_path_prefix(&same_path_prefix, worktree,
466 if (!same_path_prefix) {
467 error = got_error(GOT_ERR_PATH_PREFIX);
472 struct got_object_id *commit_id;
473 error = got_object_resolve_id_str(&commit_id, repo,
477 error = check_linear_ancestry(worktree, commit_id, repo);
482 error = got_worktree_set_base_commit_id(worktree, repo,
489 error = got_worktree_checkout_files(worktree, "", repo,
490 checkout_progress, worktree_path, check_cancelled, NULL);
494 printf("Now shut up and hack\n");
506 fprintf(stderr, "usage: %s update [-c commit] [path]\n",
512 update_progress(void *arg, unsigned char status, const char *path)
514 int *did_something = arg;
516 if (status == GOT_STATUS_EXISTS)
520 while (path[0] == '/')
522 printf("%c %s\n", status, path);
525 static const struct got_error *
526 cmd_update(int argc, char *argv[])
528 const struct got_error *error = NULL;
529 struct got_repository *repo = NULL;
530 struct got_worktree *worktree = NULL;
531 char *worktree_path = NULL, *path = NULL;
532 struct got_object_id *commit_id = NULL;
533 char *commit_id_str = NULL;
534 int ch, did_something = 0;
536 while ((ch = getopt(argc, argv, "c:")) != -1) {
539 commit_id_str = strdup(optarg);
540 if (commit_id_str == NULL)
541 return got_error_from_errno("strdup");
553 if (pledge("stdio rpath wpath cpath fattr flock proc exec sendfd "
554 "unveil", NULL) == -1)
557 worktree_path = getcwd(NULL, 0);
558 if (worktree_path == NULL) {
559 error = got_error_from_errno("getcwd");
562 error = got_worktree_open(&worktree, worktree_path);
569 error = got_error_from_errno("strdup");
572 } else if (argc == 1) {
573 error = got_worktree_resolve_path(&path, worktree, argv[0]);
579 error = got_repo_open(&repo, got_worktree_get_repo_path(worktree));
583 error = apply_unveil(got_repo_get_path(repo), 0,
584 got_worktree_get_root_path(worktree), 0, NULL);
588 if (commit_id_str == NULL) {
589 struct got_reference *head_ref;
590 error = got_ref_open(&head_ref, repo, GOT_REF_HEAD, 0);
593 error = got_ref_resolve(&commit_id, repo, head_ref);
596 error = got_object_id_str(&commit_id_str, commit_id);
600 error = got_object_resolve_id_str(&commit_id, repo,
606 error = check_linear_ancestry(worktree, commit_id, repo);
610 if (got_object_id_cmp(got_worktree_get_base_commit_id(worktree),
612 error = got_worktree_set_base_commit_id(worktree, repo,
618 error = got_worktree_checkout_files(worktree, path, repo,
619 update_progress, &did_something, check_cancelled, NULL);
624 printf("Updated to commit %s\n", commit_id_str);
626 printf("Already up-to-date\n");
635 static const struct got_error *
636 print_patch(struct got_commit_object *commit, struct got_object_id *id,
637 int diff_context, struct got_repository *repo)
639 const struct got_error *err = NULL;
640 struct got_tree_object *tree1 = NULL, *tree2;
641 struct got_object_qid *qid;
642 char *id_str1 = NULL, *id_str2;
644 err = got_object_open_as_tree(&tree2, repo,
645 got_object_commit_get_tree_id(commit));
649 qid = SIMPLEQ_FIRST(got_object_commit_get_parent_ids(commit));
651 struct got_commit_object *pcommit;
653 err = got_object_open_as_commit(&pcommit, repo, qid->id);
657 err = got_object_open_as_tree(&tree1, repo,
658 got_object_commit_get_tree_id(pcommit));
659 got_object_commit_close(pcommit);
663 err = got_object_id_str(&id_str1, qid->id);
668 err = got_object_id_str(&id_str2, id);
672 printf("diff %s %s\n", id_str1 ? id_str1 : "/dev/null", id_str2);
673 err = got_diff_tree(tree1, tree2, "", "", diff_context, repo, stdout);
676 got_object_tree_close(tree1);
677 got_object_tree_close(tree2);
684 get_datestr(time_t *time, char *datebuf)
686 char *p, *s = ctime_r(time, datebuf);
693 static const struct got_error *
694 print_commit(struct got_commit_object *commit, struct got_object_id *id,
695 struct got_repository *repo, int show_patch, int diff_context,
696 struct got_reflist_head *refs)
698 const struct got_error *err = NULL;
699 char *id_str, *datestr, *logmsg0, *logmsg, *line;
701 time_t committer_time;
702 const char *author, *committer;
703 char *refs_str = NULL;
704 struct got_reflist_entry *re;
706 SIMPLEQ_FOREACH(re, refs, entry) {
709 if (got_object_id_cmp(re->id, id) != 0)
711 name = got_ref_get_name(re->ref);
712 if (strcmp(name, GOT_REF_HEAD) == 0)
714 if (strncmp(name, "refs/", 5) == 0)
716 if (strncmp(name, "got/", 4) == 0)
718 if (strncmp(name, "heads/", 6) == 0)
720 if (strncmp(name, "remotes/", 8) == 0)
723 if (asprintf(&refs_str, "%s%s%s", s ? s : "", s ? ", " : "",
725 err = got_error_from_errno("asprintf");
731 err = got_object_id_str(&id_str, id);
735 printf("-----------------------------------------------\n");
736 printf("commit %s%s%s%s\n", id_str, refs_str ? " (" : "",
737 refs_str ? refs_str : "", refs_str ? ")" : "");
742 printf("from: %s\n", got_object_commit_get_author(commit));
743 committer_time = got_object_commit_get_committer_time(commit);
744 datestr = get_datestr(&committer_time, datebuf);
745 printf("date: %s UTC\n", datestr);
746 author = got_object_commit_get_author(commit);
747 committer = got_object_commit_get_committer(commit);
748 if (strcmp(author, committer) != 0)
749 printf("via: %s\n", committer);
750 if (got_object_commit_get_nparents(commit) > 1) {
751 const struct got_object_id_queue *parent_ids;
752 struct got_object_qid *qid;
754 parent_ids = got_object_commit_get_parent_ids(commit);
755 SIMPLEQ_FOREACH(qid, parent_ids, entry) {
756 err = got_object_id_str(&id_str, qid->id);
759 printf("parent %d: %s\n", n++, id_str);
764 logmsg0 = strdup(got_object_commit_get_logmsg(commit));
766 return got_error_from_errno("strdup");
770 line = strsep(&logmsg, "\n");
772 printf(" %s\n", line);
777 err = print_patch(commit, id, diff_context, repo);
782 if (fflush(stdout) != 0 && err == NULL)
783 err = got_error_from_errno("fflush");
787 static const struct got_error *
788 print_commits(struct got_object_id *root_id, struct got_repository *repo,
789 char *path, int show_patch, int diff_context, int limit,
790 int first_parent_traversal, struct got_reflist_head *refs)
792 const struct got_error *err;
793 struct got_commit_graph *graph;
795 err = got_commit_graph_open(&graph, root_id, path,
796 first_parent_traversal, repo);
799 err = got_commit_graph_iter_start(graph, root_id, repo);
803 struct got_commit_object *commit;
804 struct got_object_id *id;
806 if (sigint_received || sigpipe_received)
809 err = got_commit_graph_iter_next(&id, graph);
811 if (err->code == GOT_ERR_ITER_COMPLETED) {
815 if (err->code != GOT_ERR_ITER_NEED_MORE)
817 err = got_commit_graph_fetch_commits(graph, 1, repo);
826 err = got_object_open_as_commit(&commit, repo, id);
829 err = print_commit(commit, id, repo, show_patch, diff_context,
831 got_object_commit_close(commit);
832 if (err || (limit && --limit == 0))
836 got_commit_graph_close(graph);
843 fprintf(stderr, "usage: %s log [-c commit] [-C number] [-f] [ -l N ] [-p] "
844 "[-r repository-path] [path]\n", getprogname());
848 static const struct got_error *
849 cmd_log(int argc, char *argv[])
851 const struct got_error *error;
852 struct got_repository *repo = NULL;
853 struct got_worktree *worktree = NULL;
854 struct got_commit_object *commit = NULL;
855 struct got_object_id *id = NULL;
856 char *repo_path = NULL, *path = NULL, *cwd = NULL, *in_repo_path = NULL;
857 char *start_commit = NULL;
858 int diff_context = 3, ch;
859 int show_patch = 0, limit = 0, first_parent_traversal = 0;
861 struct got_reflist_head refs;
866 if (pledge("stdio rpath wpath cpath flock proc exec sendfd unveil",
872 while ((ch = getopt(argc, argv, "pc:C:l:fr:")) != -1) {
878 start_commit = optarg;
881 diff_context = strtonum(optarg, 0, GOT_DIFF_MAX_CONTEXT,
884 err(1, "-C option %s", errstr);
887 limit = strtonum(optarg, 1, INT_MAX, &errstr);
889 err(1, "-l option %s", errstr);
892 first_parent_traversal = 1;
895 repo_path = realpath(optarg, NULL);
896 if (repo_path == NULL)
898 got_path_strip_trailing_slashes(repo_path);
909 cwd = getcwd(NULL, 0);
911 error = got_error_from_errno("getcwd");
915 error = got_worktree_open(&worktree, cwd);
916 if (error && error->code != GOT_ERR_NOT_WORKTREE)
923 error = got_error_from_errno("strdup");
926 } else if (argc == 1) {
928 error = got_worktree_resolve_path(&path, worktree,
933 path = strdup(argv[0]);
935 error = got_error_from_errno("strdup");
942 if (repo_path == NULL) {
943 repo_path = worktree ?
944 strdup(got_worktree_get_repo_path(worktree)) : strdup(cwd);
946 if (repo_path == NULL) {
947 error = got_error_from_errno("strdup");
951 error = got_repo_open(&repo, repo_path);
955 error = apply_unveil(got_repo_get_path(repo), 1,
956 worktree ? got_worktree_get_root_path(worktree) : NULL, 0, NULL);
960 if (start_commit == NULL) {
961 struct got_reference *head_ref;
962 error = got_ref_open(&head_ref, repo, GOT_REF_HEAD, 0);
965 error = got_ref_resolve(&id, repo, head_ref);
966 got_ref_close(head_ref);
969 error = got_object_open_as_commit(&commit, repo, id);
971 struct got_reference *ref;
972 error = got_ref_open(&ref, repo, start_commit, 0);
975 error = got_ref_resolve(&id, repo, ref);
979 error = got_object_get_type(&obj_type, repo, id);
982 if (obj_type == GOT_OBJ_TYPE_TAG) {
983 struct got_tag_object *tag;
984 error = got_object_open_as_tag(&tag, repo, id);
987 if (got_object_tag_get_object_type(tag) !=
988 GOT_OBJ_TYPE_COMMIT) {
989 got_object_tag_close(tag);
990 error = got_error(GOT_ERR_OBJ_TYPE);
994 id = got_object_id_dup(
995 got_object_tag_get_object_id(tag));
997 error = got_error_from_errno(
998 "got_object_id_dup");
999 got_object_tag_close(tag);
1002 } else if (obj_type != GOT_OBJ_TYPE_COMMIT) {
1003 error = got_error(GOT_ERR_OBJ_TYPE);
1006 error = got_object_open_as_commit(&commit, repo, id);
1010 if (commit == NULL) {
1011 error = got_object_resolve_id_str(&id, repo,
1020 error = got_repo_map_path(&in_repo_path, repo, path, 1);
1025 path = in_repo_path;
1028 error = got_ref_list(&refs, repo);
1032 error = print_commits(id, repo, path, show_patch,
1033 diff_context, limit, first_parent_traversal, &refs);
1040 got_worktree_close(worktree);
1042 const struct got_error *repo_error;
1043 repo_error = got_repo_close(repo);
1047 got_ref_list_free(&refs);
1054 fprintf(stderr, "usage: %s diff [-C number] [-r repository-path] "
1055 "[object1 object2 | path]\n", getprogname());
1059 struct print_diff_arg {
1060 struct got_repository *repo;
1061 struct got_worktree *worktree;
1067 static const struct got_error *
1068 print_diff(void *arg, unsigned char status, const char *path,
1069 struct got_object_id *id)
1071 struct print_diff_arg *a = arg;
1072 const struct got_error *err = NULL;
1073 struct got_blob_object *blob1 = NULL;
1075 char *abspath = NULL;
1078 if (status != GOT_STATUS_MODIFY && status != GOT_STATUS_ADD &&
1079 status != GOT_STATUS_DELETE && status != GOT_STATUS_CONFLICT)
1082 if (!a->header_shown) {
1083 printf("diff %s %s\n", a->id_str,
1084 got_worktree_get_root_path(a->worktree));
1085 a->header_shown = 1;
1088 if (status != GOT_STATUS_ADD) {
1089 err = got_object_open_as_blob(&blob1, a->repo, id, 8192);
1095 if (status != GOT_STATUS_DELETE) {
1096 if (asprintf(&abspath, "%s/%s",
1097 got_worktree_get_root_path(a->worktree), path) == -1) {
1098 err = got_error_from_errno("asprintf");
1102 f2 = fopen(abspath, "r");
1104 err = got_error_from_errno2("fopen", abspath);
1107 if (lstat(abspath, &sb) == -1) {
1108 err = got_error_from_errno2("lstat", abspath);
1114 err = got_diff_blob_file(blob1, f2, sb.st_size, path, a->diff_context,
1118 got_object_blob_close(blob1);
1119 if (f2 && fclose(f2) != 0 && err == NULL)
1120 err = got_error_from_errno("fclose");
1125 static const struct got_error *
1126 cmd_diff(int argc, char *argv[])
1128 const struct got_error *error;
1129 struct got_repository *repo = NULL;
1130 struct got_worktree *worktree = NULL;
1131 char *cwd = NULL, *repo_path = NULL;
1132 struct got_object_id *id1 = NULL, *id2 = NULL;
1133 char *id_str1 = NULL, *id_str2 = NULL;
1135 int diff_context = 3, ch;
1140 if (pledge("stdio rpath wpath cpath flock proc exec sendfd unveil",
1145 while ((ch = getopt(argc, argv, "C:r:")) != -1) {
1148 diff_context = strtonum(optarg, 1, INT_MAX, &errstr);
1150 err(1, "-C option %s", errstr);
1153 repo_path = realpath(optarg, NULL);
1154 if (repo_path == NULL)
1155 err(1, "-r option");
1156 got_path_strip_trailing_slashes(repo_path);
1167 cwd = getcwd(NULL, 0);
1169 error = got_error_from_errno("getcwd");
1172 error = got_worktree_open(&worktree, cwd);
1173 if (error && error->code != GOT_ERR_NOT_WORKTREE)
1176 if (worktree == NULL) {
1177 error = got_error(GOT_ERR_NOT_WORKTREE);
1182 "-r option can't be used when diffing a work tree");
1183 repo_path = strdup(got_worktree_get_repo_path(worktree));
1184 if (repo_path == NULL) {
1185 error = got_error_from_errno("strdup");
1189 error = got_worktree_resolve_path(&path, worktree,
1196 error = got_error_from_errno("strdup");
1200 } else if (argc == 2) {
1206 if (repo_path == NULL) {
1207 repo_path = getcwd(NULL, 0);
1208 if (repo_path == NULL)
1209 return got_error_from_errno("getcwd");
1212 error = got_repo_open(&repo, repo_path);
1217 error = apply_unveil(got_repo_get_path(repo), 1,
1218 worktree ? got_worktree_get_root_path(worktree) : NULL, 0, NULL);
1223 struct print_diff_arg arg;
1225 error = got_object_id_str(&id_str,
1226 got_worktree_get_base_commit_id(worktree));
1230 arg.worktree = worktree;
1231 arg.diff_context = diff_context;
1232 arg.id_str = id_str;
1233 arg.header_shown = 0;
1235 error = got_worktree_status(worktree, path, repo, print_diff,
1236 &arg, check_cancelled, NULL);
1241 error = got_object_resolve_id_str(&id1, repo, id_str1);
1245 error = got_object_resolve_id_str(&id2, repo, id_str2);
1249 error = got_object_get_type(&type1, repo, id1);
1253 error = got_object_get_type(&type2, repo, id2);
1257 if (type1 != type2) {
1258 error = got_error(GOT_ERR_OBJ_TYPE);
1263 case GOT_OBJ_TYPE_BLOB:
1264 error = got_diff_objects_as_blobs(id1, id2, NULL, NULL,
1265 diff_context, repo, stdout);
1267 case GOT_OBJ_TYPE_TREE:
1268 error = got_diff_objects_as_trees(id1, id2, "", "",
1269 diff_context, repo, stdout);
1271 case GOT_OBJ_TYPE_COMMIT:
1272 printf("diff %s %s\n", id_str1 ? id_str1 : "/dev/null",
1274 error = got_diff_objects_as_commits(id1, id2, diff_context,
1278 error = got_error(GOT_ERR_OBJ_TYPE);
1286 got_worktree_close(worktree);
1288 const struct got_error *repo_error;
1289 repo_error = got_repo_close(repo);
1300 "usage: %s blame [-c commit] [-r repository-path] path\n",
1305 static const struct got_error *
1306 cmd_blame(int argc, char *argv[])
1308 const struct got_error *error;
1309 struct got_repository *repo = NULL;
1310 struct got_worktree *worktree = NULL;
1311 char *path, *cwd = NULL, *repo_path = NULL, *in_repo_path = NULL;
1312 struct got_object_id *commit_id = NULL;
1313 char *commit_id_str = NULL;
1317 if (pledge("stdio rpath wpath cpath flock proc exec sendfd unveil",
1322 while ((ch = getopt(argc, argv, "c:r:")) != -1) {
1325 commit_id_str = optarg;
1328 repo_path = realpath(optarg, NULL);
1329 if (repo_path == NULL)
1330 err(1, "-r option");
1331 got_path_strip_trailing_slashes(repo_path);
1347 cwd = getcwd(NULL, 0);
1349 error = got_error_from_errno("getcwd");
1352 if (repo_path == NULL) {
1353 error = got_worktree_open(&worktree, cwd);
1354 if (error && error->code != GOT_ERR_NOT_WORKTREE)
1360 strdup(got_worktree_get_repo_path(worktree));
1361 if (repo_path == NULL)
1362 error = got_error_from_errno("strdup");
1366 repo_path = strdup(cwd);
1367 if (repo_path == NULL) {
1368 error = got_error_from_errno("strdup");
1374 error = got_repo_open(&repo, repo_path);
1378 error = apply_unveil(got_repo_get_path(repo), 1, NULL, 0, NULL);
1383 const char *prefix = got_worktree_get_path_prefix(worktree);
1384 char *p, *worktree_subdir = cwd +
1385 strlen(got_worktree_get_root_path(worktree));
1386 if (asprintf(&p, "%s%s%s%s%s",
1387 prefix, (strcmp(prefix, "/") != 0) ? "/" : "",
1388 worktree_subdir, worktree_subdir[0] ? "/" : "",
1390 error = got_error_from_errno("asprintf");
1393 error = got_repo_map_path(&in_repo_path, repo, p, 0);
1396 error = got_repo_map_path(&in_repo_path, repo, path, 1);
1401 if (commit_id_str == NULL) {
1402 struct got_reference *head_ref;
1403 error = got_ref_open(&head_ref, repo, GOT_REF_HEAD, 0);
1406 error = got_ref_resolve(&commit_id, repo, head_ref);
1407 got_ref_close(head_ref);
1411 error = got_object_resolve_id_str(&commit_id, repo,
1417 error = got_blame(in_repo_path, commit_id, repo, stdout);
1424 got_worktree_close(worktree);
1426 const struct got_error *repo_error;
1427 repo_error = got_repo_close(repo);
1438 "usage: %s tree [-c commit] [-r repository-path] [-iR] path\n",
1444 print_entry(struct got_tree_entry *te, const char *id, const char *path,
1445 const char *root_path)
1447 int is_root_path = (strcmp(path, root_path) == 0);
1449 path += strlen(root_path);
1450 while (path[0] == '/')
1453 printf("%s%s%s%s%s\n", id ? id : "", path,
1454 is_root_path ? "" : "/", te->name,
1455 S_ISDIR(te->mode) ? "/" : ((te->mode & S_IXUSR) ? "*" : ""));
1458 static const struct got_error *
1459 print_tree(const char *path, struct got_object_id *commit_id,
1460 int show_ids, int recurse, const char *root_path,
1461 struct got_repository *repo)
1463 const struct got_error *err = NULL;
1464 struct got_object_id *tree_id = NULL;
1465 struct got_tree_object *tree = NULL;
1466 const struct got_tree_entries *entries;
1467 struct got_tree_entry *te;
1469 err = got_object_id_by_path(&tree_id, repo, commit_id, path);
1473 err = got_object_open_as_tree(&tree, repo, tree_id);
1476 entries = got_object_tree_get_entries(tree);
1477 te = SIMPLEQ_FIRST(&entries->head);
1481 if (sigint_received || sigpipe_received)
1486 err = got_object_id_str(&id_str, te->id);
1489 if (asprintf(&id, "%s ", id_str) == -1) {
1490 err = got_error_from_errno("asprintf");
1496 print_entry(te, id, path, root_path);
1499 if (recurse && S_ISDIR(te->mode)) {
1501 if (asprintf(&child_path, "%s%s%s", path,
1502 path[0] == '/' && path[1] == '\0' ? "" : "/",
1504 err = got_error_from_errno("asprintf");
1507 err = print_tree(child_path, commit_id, show_ids, 1,
1514 te = SIMPLEQ_NEXT(te, entry);
1518 got_object_tree_close(tree);
1523 static const struct got_error *
1524 cmd_tree(int argc, char *argv[])
1526 const struct got_error *error;
1527 struct got_repository *repo = NULL;
1528 struct got_worktree *worktree = NULL;
1530 char *cwd = NULL, *repo_path = NULL, *in_repo_path = NULL;
1531 struct got_object_id *commit_id = NULL;
1532 char *commit_id_str = NULL;
1533 int show_ids = 0, recurse = 0;
1537 if (pledge("stdio rpath wpath cpath flock proc exec sendfd unveil",
1542 while ((ch = getopt(argc, argv, "c:r:iR")) != -1) {
1545 commit_id_str = optarg;
1548 repo_path = realpath(optarg, NULL);
1549 if (repo_path == NULL)
1550 err(1, "-r option");
1551 got_path_strip_trailing_slashes(repo_path);
1575 cwd = getcwd(NULL, 0);
1577 error = got_error_from_errno("getcwd");
1580 if (repo_path == NULL) {
1581 error = got_worktree_open(&worktree, cwd);
1582 if (error && error->code != GOT_ERR_NOT_WORKTREE)
1588 strdup(got_worktree_get_repo_path(worktree));
1589 if (repo_path == NULL)
1590 error = got_error_from_errno("strdup");
1594 repo_path = strdup(cwd);
1595 if (repo_path == NULL) {
1596 error = got_error_from_errno("strdup");
1602 error = got_repo_open(&repo, repo_path);
1606 error = apply_unveil(got_repo_get_path(repo), 1, NULL, 0, NULL);
1612 char *p, *worktree_subdir = cwd +
1613 strlen(got_worktree_get_root_path(worktree));
1614 if (asprintf(&p, "%s/%s",
1615 got_worktree_get_path_prefix(worktree),
1616 worktree_subdir) == -1) {
1617 error = got_error_from_errno("asprintf");
1620 error = got_repo_map_path(&in_repo_path, repo, p, 1);
1627 if (in_repo_path == NULL) {
1628 error = got_repo_map_path(&in_repo_path, repo, path, 1);
1633 if (commit_id_str == NULL) {
1634 struct got_reference *head_ref;
1635 error = got_ref_open(&head_ref, repo, GOT_REF_HEAD, 0);
1638 error = got_ref_resolve(&commit_id, repo, head_ref);
1639 got_ref_close(head_ref);
1643 error = got_object_resolve_id_str(&commit_id, repo,
1649 error = print_tree(in_repo_path, commit_id, show_ids, recurse,
1650 in_repo_path, repo);
1657 got_worktree_close(worktree);
1659 const struct got_error *repo_error;
1660 repo_error = got_repo_close(repo);
1670 fprintf(stderr, "usage: %s status [path]\n", getprogname());
1674 static const struct got_error *
1675 print_status(void *arg, unsigned char status, const char *path,
1676 struct got_object_id *id)
1678 printf("%c %s\n", status, path);
1682 static const struct got_error *
1683 cmd_status(int argc, char *argv[])
1685 const struct got_error *error = NULL;
1686 struct got_repository *repo = NULL;
1687 struct got_worktree *worktree = NULL;
1688 char *cwd = NULL, *path = NULL;
1691 while ((ch = getopt(argc, argv, "")) != -1) {
1703 if (pledge("stdio rpath wpath cpath flock proc exec sendfd unveil",
1707 cwd = getcwd(NULL, 0);
1709 error = got_error_from_errno("getcwd");
1713 error = got_worktree_open(&worktree, cwd);
1720 error = got_error_from_errno("strdup");
1723 } else if (argc == 1) {
1724 error = got_worktree_resolve_path(&path, worktree, argv[0]);
1730 error = got_repo_open(&repo, got_worktree_get_repo_path(worktree));
1734 error = apply_unveil(got_repo_get_path(repo), 1,
1735 got_worktree_get_root_path(worktree), 0, NULL);
1739 error = got_worktree_status(worktree, path, repo, print_status, NULL,
1740 check_cancelled, NULL);
1751 "usage: %s ref [-r repository] -l | -d name | name object\n",
1756 static const struct got_error *
1757 list_refs(struct got_repository *repo)
1759 static const struct got_error *err = NULL;
1760 struct got_reflist_head refs;
1761 struct got_reflist_entry *re;
1763 SIMPLEQ_INIT(&refs);
1764 err = got_ref_list(&refs, repo);
1768 SIMPLEQ_FOREACH(re, &refs, entry) {
1770 refstr = got_ref_to_str(re->ref);
1772 return got_error_from_errno("got_ref_to_str");
1773 printf("%s: %s\n", got_ref_get_name(re->ref), refstr);
1777 got_ref_list_free(&refs);
1781 static const struct got_error *
1782 delete_ref(struct got_repository *repo, const char *refname)
1784 const struct got_error *err = NULL;
1785 struct got_reference *ref;
1787 err = got_ref_open(&ref, repo, refname, 0);
1791 err = got_ref_delete(ref, repo);
1796 static const struct got_error *
1797 add_ref(struct got_repository *repo, const char *refname, const char *id_str)
1799 const struct got_error *err = NULL;
1800 struct got_object_id *id;
1801 struct got_reference *ref = NULL;
1803 err = got_object_resolve_id_str(&id, repo, id_str);
1807 err = got_ref_alloc(&ref, refname, id);
1811 err = got_ref_write(ref, repo);
1819 static const struct got_error *
1820 cmd_ref(int argc, char *argv[])
1822 const struct got_error *error = NULL;
1823 struct got_repository *repo = NULL;
1824 struct got_worktree *worktree = NULL;
1825 char *cwd = NULL, *repo_path = NULL;
1826 int ch, do_list = 0;
1827 const char *delref = NULL;
1829 /* TODO: Add -s option for adding symbolic references. */
1830 while ((ch = getopt(argc, argv, "d:r:l")) != -1) {
1836 repo_path = realpath(optarg, NULL);
1837 if (repo_path == NULL)
1838 err(1, "-r option");
1839 got_path_strip_trailing_slashes(repo_path);
1850 if (do_list && delref)
1851 errx(1, "-l and -d options are mutually exclusive\n");
1856 if (do_list || delref) {
1859 } else if (argc != 2)
1864 if (pledge("stdio rpath wpath flock proc exec sendfd unveil",
1868 if (pledge("stdio rpath wpath cpath fattr flock proc exec "
1869 "sendfd unveil", NULL) == -1)
1873 cwd = getcwd(NULL, 0);
1875 error = got_error_from_errno("getcwd");
1879 if (repo_path == NULL) {
1880 error = got_worktree_open(&worktree, cwd);
1881 if (error && error->code != GOT_ERR_NOT_WORKTREE)
1887 strdup(got_worktree_get_repo_path(worktree));
1888 if (repo_path == NULL)
1889 error = got_error_from_errno("strdup");
1893 repo_path = strdup(cwd);
1894 if (repo_path == NULL) {
1895 error = got_error_from_errno("strdup");
1901 error = got_repo_open(&repo, repo_path);
1905 error = apply_unveil(got_repo_get_path(repo), do_list,
1906 worktree ? got_worktree_get_root_path(worktree) : NULL, 0, NULL);
1911 error = list_refs(repo);
1913 error = delete_ref(repo, delref);
1915 error = add_ref(repo, argv[0], argv[1]);
1918 got_repo_close(repo);
1920 got_worktree_close(worktree);
1929 fprintf(stderr, "usage: %s add file-path ...\n", getprogname());
1933 static const struct got_error *
1934 cmd_add(int argc, char *argv[])
1936 const struct got_error *error = NULL;
1937 struct got_repository *repo = NULL;
1938 struct got_worktree *worktree = NULL;
1940 struct got_pathlist_head paths;
1941 struct got_pathlist_entry *pe;
1946 while ((ch = getopt(argc, argv, "")) != -1) {
1960 /* make sure each file exists before doing anything halfway */
1961 for (x = 0; x < argc; x++) {
1962 char *path = realpath(argv[x], NULL);
1964 error = got_error_from_errno2("realpath", argv[x]);
1970 cwd = getcwd(NULL, 0);
1972 error = got_error_from_errno("getcwd");
1976 error = got_worktree_open(&worktree, cwd);
1980 error = got_repo_open(&repo, got_worktree_get_repo_path(worktree));
1984 error = apply_unveil(got_repo_get_path(repo), 1,
1985 got_worktree_get_root_path(worktree), 0, NULL);
1989 for (x = 0; x < argc; x++) {
1990 char *path = realpath(argv[x], NULL);
1992 error = got_error_from_errno2("realpath", argv[x]);
1996 got_path_strip_trailing_slashes(path);
1997 error = got_pathlist_insert(&pe, &paths, path, NULL);
2003 error = got_worktree_schedule_add(worktree, &paths, print_status,
2007 got_repo_close(repo);
2009 got_worktree_close(worktree);
2010 TAILQ_FOREACH(pe, &paths, entry)
2011 free((char *)pe->path);
2012 got_pathlist_free(&paths);
2020 fprintf(stderr, "usage: %s rm [-f] file-path\n", getprogname());
2024 static const struct got_error *
2025 cmd_rm(int argc, char *argv[])
2027 const struct got_error *error = NULL;
2028 struct got_worktree *worktree = NULL;
2029 struct got_repository *repo = NULL;
2030 char *cwd = NULL, *path = NULL;
2031 int ch, delete_local_mods = 0;
2033 while ((ch = getopt(argc, argv, "f")) != -1) {
2036 delete_local_mods = 1;
2050 path = realpath(argv[0], NULL);
2052 error = got_error_from_errno2("realpath", argv[0]);
2055 got_path_strip_trailing_slashes(path);
2057 cwd = getcwd(NULL, 0);
2059 error = got_error_from_errno("getcwd");
2062 error = got_worktree_open(&worktree, cwd);
2066 error = got_repo_open(&repo, got_worktree_get_repo_path(worktree));
2070 error = apply_unveil(got_repo_get_path(repo), 1,
2071 got_worktree_get_root_path(worktree), 0, NULL);
2075 error = got_worktree_schedule_delete(worktree, path, delete_local_mods,
2076 print_status, NULL, repo);
2081 got_repo_close(repo);
2083 got_worktree_close(worktree);
2092 fprintf(stderr, "usage: %s revert file-path\n", getprogname());
2097 revert_progress(void *arg, unsigned char status, const char *path)
2099 while (path[0] == '/')
2101 printf("%c %s\n", status, path);
2104 static const struct got_error *
2105 cmd_revert(int argc, char *argv[])
2107 const struct got_error *error = NULL;
2108 struct got_worktree *worktree = NULL;
2109 struct got_repository *repo = NULL;
2110 char *cwd = NULL, *path = NULL;
2113 while ((ch = getopt(argc, argv, "")) != -1) {
2127 path = realpath(argv[0], NULL);
2129 error = got_error_from_errno2("realpath", argv[0]);
2132 got_path_strip_trailing_slashes(path);
2134 cwd = getcwd(NULL, 0);
2136 error = got_error_from_errno("getcwd");
2139 error = got_worktree_open(&worktree, cwd);
2143 error = got_repo_open(&repo, got_worktree_get_repo_path(worktree));
2147 error = apply_unveil(got_repo_get_path(repo), 1,
2148 got_worktree_get_root_path(worktree), 0, NULL);
2152 error = got_worktree_revert(worktree, path,
2153 revert_progress, NULL, repo);
2158 got_repo_close(repo);
2160 got_worktree_close(worktree);
2169 fprintf(stderr, "usage: %s commit [-m msg] file-path\n", getprogname());
2174 spawn_editor(const char *editor, const char *file)
2177 sig_t sighup, sigint, sigquit;
2180 sighup = signal(SIGHUP, SIG_IGN);
2181 sigint = signal(SIGINT, SIG_IGN);
2182 sigquit = signal(SIGQUIT, SIG_IGN);
2184 switch (pid = fork()) {
2188 execl(editor, editor, file, (char *)NULL);
2192 while (waitpid(pid, &st, 0) == -1)
2197 (void)signal(SIGHUP, sighup);
2198 (void)signal(SIGINT, sigint);
2199 (void)signal(SIGQUIT, sigquit);
2201 if (!WIFEXITED(st)) {
2206 return WEXITSTATUS(st);
2209 struct collect_commit_logmsg_arg {
2210 const char *cmdline_log;
2212 const char *worktree_path;
2217 static const struct got_error *
2218 collect_commit_logmsg(struct got_pathlist_head *commitable_paths, char **logmsg,
2221 const char *initial_content = "\n# changes to be committed:\n";
2222 struct got_pathlist_entry *pe;
2223 const struct got_error *err = NULL;
2224 char *template = NULL;
2225 struct collect_commit_logmsg_arg *a = arg;
2227 struct stat st, st2;
2230 int fd, content_changed = 0;
2232 /* if a message was specified on the command line, just use it */
2233 if (a->cmdline_log != NULL && strlen(a->cmdline_log) != 0) {
2234 len = strlen(a->cmdline_log) + 1;
2235 *logmsg = malloc(len + 1);
2236 if (*logmsg == NULL)
2237 return got_error_from_errno("malloc");
2238 strlcpy(*logmsg, a->cmdline_log, len);
2242 if (asprintf(&template, "%s/logmsg", a->worktree_path) == -1)
2243 return got_error_from_errno("asprintf");
2245 err = got_opentemp_named_fd(&a->logmsg_path, &fd, template);
2249 dprintf(fd, initial_content);
2251 TAILQ_FOREACH(pe, commitable_paths, entry) {
2252 struct got_commitable *ct = pe->data;
2253 dprintf(fd, "# %c %s\n", ct->status, pe->path);
2257 if (stat(a->logmsg_path, &st) == -1) {
2258 err = got_error_from_errno2("stat", a->logmsg_path);
2262 if (spawn_editor(a->editor, a->logmsg_path) == -1) {
2263 err = got_error_from_errno("failed spawning editor");
2267 if (stat(a->logmsg_path, &st2) == -1) {
2268 err = got_error_from_errno("stat");
2272 if (st.st_mtime == st2.st_mtime && st.st_size == st2.st_size) {
2273 unlink(a->logmsg_path);
2274 free(a->logmsg_path);
2275 a->logmsg_path = NULL;
2276 err = got_error_msg(GOT_ERR_COMMIT_MSG_EMPTY,
2277 "no changes made to commit message, aborting");
2281 /* remove comments */
2282 *logmsg = malloc(st2.st_size + 1);
2283 if (*logmsg == NULL) {
2284 err = got_error_from_errno("malloc");
2289 fp = fopen(a->logmsg_path, "r");
2290 while (fgets(buf, sizeof(buf), fp) != NULL) {
2291 if (!content_changed && strcmp(buf, initial_content) != 0)
2292 content_changed = 1;
2293 if (buf[0] == '#' || (len == 0 && buf[0] == '\n'))
2295 len = strlcat(*logmsg, buf, st2.st_size);
2299 while (len > 0 && (*logmsg)[len - 1] == '\n') {
2300 (*logmsg)[len - 1] = '\0';
2304 if (len == 0 || !content_changed) {
2305 unlink(a->logmsg_path);
2306 free(a->logmsg_path);
2307 a->logmsg_path = NULL;
2308 err = got_error_msg(GOT_ERR_COMMIT_MSG_EMPTY,
2309 "commit message cannot be empty, aborting");
2317 static const struct got_error *
2318 cmd_commit(int argc, char *argv[])
2320 const struct got_error *error = NULL;
2321 struct got_worktree *worktree = NULL;
2322 struct got_repository *repo = NULL;
2323 char *cwd = NULL, *path = NULL, *id_str = NULL;
2324 struct got_object_id *id = NULL;
2325 const char *logmsg = NULL;
2326 const char *got_author = getenv("GOT_AUTHOR");
2327 struct collect_commit_logmsg_arg cl_arg;
2328 char *editor = NULL;
2331 while ((ch = getopt(argc, argv, "m:")) != -1) {
2346 path = realpath(argv[0], NULL);
2348 error = got_error_from_errno2("realpath", argv[0]);
2351 got_path_strip_trailing_slashes(path);
2352 } else if (argc != 0)
2355 if (got_author == NULL) {
2356 /* TODO: Look current user up in password database */
2357 error = got_error(GOT_ERR_COMMIT_NO_AUTHOR);
2361 cwd = getcwd(NULL, 0);
2363 error = got_error_from_errno("getcwd");
2366 error = got_worktree_open(&worktree, cwd);
2370 error = got_repo_open(&repo, got_worktree_get_repo_path(worktree));
2374 error = apply_unveil(got_repo_get_path(repo), 0,
2375 got_worktree_get_root_path(worktree), 0, &editor);
2379 cl_arg.editor = editor;
2380 cl_arg.cmdline_log = logmsg;
2381 cl_arg.worktree_path = got_worktree_get_root_path(worktree);
2382 cl_arg.logmsg_path = NULL;
2383 error = got_worktree_commit(&id, worktree, path, got_author, NULL,
2384 collect_commit_logmsg, &cl_arg, print_status, NULL, repo);
2386 if (cl_arg.logmsg_path)
2387 fprintf(stderr, "%s: log message preserved in %s\n",
2388 getprogname(), cl_arg.logmsg_path);
2392 if (cl_arg.logmsg_path)
2393 unlink(cl_arg.logmsg_path);
2395 error = got_object_id_str(&id_str, id);
2398 printf("created commit %s\n", id_str);
2401 got_repo_close(repo);
2403 got_worktree_close(worktree);