add 'got status' command
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
diff --git a/got/got.1 b/got/got.1
index 1f262f0..374ed5e 100644
--- a/got/got.1
+++ b/got/got.1
@@ -109,8 +109,19 @@ Update the work tree to the specified
.Ar commit .
The expected argument is a SHA1 hash which corresponds to a commit object.
.El
-.\".It Cm status
-.\"Show current status of files.
+.It Cm status [ Ar worktree-path ]
+Show the current modification status of files in a worktree,
+using the following status codes:
+.Bl -column YXZ description
+.It M Ta modified file
+.It ! Ta versioned file was expected on disk but is missing
+.It ? Ta unversioned item not tracked by
+.Nm
+.El
+.Pp
+If the
+.Ar work tree path
+is omitted, use the current working directory.
.It Cm log [ Fl c Ar commit ] [ Fl C Ar number ] [ Fl f ] [ Fl l Ar N ] [ Fl p ] [ Fl r Ar repository-path ] [ path ]
Display history of a repository.
If a
diff --git a/got/got.c b/got/got.c
index bedd053..21e4910 100644
--- a/got/got.c
+++ b/got/got.c
@@ -75,6 +75,7 @@ __dead static void usage_log(void);
__dead static void usage_diff(void);
__dead static void usage_blame(void);
__dead static void usage_tree(void);
+__dead static void usage_status(void);
static const struct got_error* cmd_checkout(int, char *[]);
static const struct got_error* cmd_update(int, char *[]);
@@ -82,9 +83,7 @@ static const struct got_error* cmd_log(int, char *[]);
static const struct got_error* cmd_diff(int, char *[]);
static const struct got_error* cmd_blame(int, char *[]);
static const struct got_error* cmd_tree(int, char *[]);
-#ifdef notyet
static const struct got_error* cmd_status(int, char *[]);
-#endif
static struct cmd got_commands[] = {
{ "checkout", cmd_checkout, usage_checkout,
@@ -99,10 +98,8 @@ static struct cmd got_commands[] = {
" show when lines in a file were changed" },
{ "tree", cmd_tree, usage_tree,
" list files and directories in repository" },
-#ifdef notyet
{ "status", cmd_status, usage_status,
"show modification status of files" },
-#endif
};
int
@@ -218,7 +215,7 @@ checkout_progress(void *arg, unsigned char status, const char *path)
}
static const struct got_error *
-checkout_cancel(void *arg)
+check_cancelled(void *arg)
{
if (sigint_received || sigpipe_received)
return got_error(GOT_ERR_CANCELLED);
@@ -410,7 +407,7 @@ cmd_checkout(int argc, char *argv[])
}
error = got_worktree_checkout_files(worktree, repo,
- checkout_progress, worktree_path, checkout_cancel, NULL);
+ checkout_progress, worktree_path, check_cancelled, NULL);
if (error != NULL)
goto done;
@@ -535,7 +532,7 @@ cmd_update(int argc, char *argv[])
}
error = got_worktree_checkout_files(worktree, repo,
- update_progress, &did_something, checkout_cancel, NULL);
+ update_progress, &did_something, check_cancelled, NULL);
if (error != NULL)
goto done;
@@ -1349,83 +1346,74 @@ done:
return error;
}
-#ifdef notyet
-static const struct got_error *
-cmd_status(int argc __unused, char *argv[] __unused)
+__dead static void
+usage_status(void)
{
- git_repository *repo = NULL;
- git_status_list *status;
- git_status_options statusopts;
- size_t i;
-
- git_libgit2_init();
+ fprintf(stderr, "usage: %s status [worktree-path]\n", getprogname());
+ exit(1);
+}
- if (git_repository_open_ext(&repo, ".", 0, NULL))
- errx(1, "git_repository_open: %s", giterr_last()->message);
+static void
+print_status(void *arg, unsigned char status, const char *path)
+{
+ printf("%c %s\n", status, path);
+}
- if (git_repository_is_bare(repo))
- errx(1, "bar repository");
+static const struct got_error *
+cmd_status(int argc, char *argv[])
+{
+ const struct got_error *error = NULL;
+ struct got_repository *repo = NULL;
+ struct got_worktree *worktree = NULL;
+ char *worktree_path = NULL;
+ int ch;
- if (git_status_init_options(&statusopts, GIT_STATUS_OPTIONS_VERSION))
- errx(1, "git_status_init_options: %s", giterr_last()->message);
+ while ((ch = getopt(argc, argv, "")) != -1) {
+ switch (ch) {
+ default:
+ usage();
+ /* NOTREACHED */
+ }
+ }
- statusopts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
- statusopts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
- GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX |
- GIT_STATUS_OPT_SORT_CASE_SENSITIVELY;
+ argc -= optind;
+ argv += optind;
- if (git_status_list_new(&status, repo, &statusopts))
- errx(1, "git_status_list_new: %s", giterr_last()->message);
+#ifndef PROFILE
+ if (pledge("stdio rpath wpath cpath flock proc exec sendfd unveil",
+ NULL) == -1)
+ err(1, "pledge");
+#endif
+ if (argc == 0) {
+ worktree_path = getcwd(NULL, 0);
+ if (worktree_path == NULL) {
+ error = got_error_from_errno();
+ goto done;
+ }
+ } else if (argc == 1) {
+ worktree_path = realpath(argv[0], NULL);
+ if (worktree_path == NULL) {
+ error = got_error_from_errno();
+ goto done;
+ }
+ } else
+ usage_status();
- for (i = 0; i < git_status_list_entrycount(status); i++) {
- const git_status_entry *se;
+ error = got_worktree_open(&worktree, worktree_path);
+ if (error != NULL)
+ goto done;
- se = git_status_byindex(status, i);
- switch (se->status) {
- case GIT_STATUS_WT_NEW:
- printf("? %s\n", se->index_to_workdir->new_file.path);
- break;
- case GIT_STATUS_WT_MODIFIED:
- printf("M %s\n", se->index_to_workdir->new_file.path);
- break;
- case GIT_STATUS_WT_DELETED:
- printf("R %s\n", se->index_to_workdir->new_file.path);
- break;
- case GIT_STATUS_WT_RENAMED:
- printf("m %s -> %s\n",
- se->index_to_workdir->old_file.path,
- se->index_to_workdir->new_file.path);
- break;
- case GIT_STATUS_WT_TYPECHANGE:
- printf("t %s\n", se->index_to_workdir->new_file.path);
- break;
- case GIT_STATUS_INDEX_NEW:
- printf("A %s\n", se->head_to_index->new_file.path);
- break;
- case GIT_STATUS_INDEX_MODIFIED:
- printf("M %s\n", se->head_to_index->old_file.path);
- break;
- case GIT_STATUS_INDEX_DELETED:
- printf("R %s\n", se->head_to_index->old_file.path);
- break;
- case GIT_STATUS_INDEX_RENAMED:
- printf("m %s -> %s\n",
- se->head_to_index->old_file.path,
- se->head_to_index->new_file.path);
- break;
- case GIT_STATUS_INDEX_TYPECHANGE:
- printf("t %s\n", se->head_to_index->old_file.path);
- break;
- case GIT_STATUS_CURRENT:
- default:
- break;
- }
- }
+ error = got_repo_open(&repo, got_worktree_get_repo_path(worktree));
+ if (error != NULL)
+ goto done;
- git_status_list_free(status);
- git_repository_free(repo);
- git_libgit2_shutdown();
+ error = apply_unveil(got_repo_get_path(repo), worktree_path);
+ if (error)
+ goto done;
- return 0;
+ error = got_worktree_status(worktree, repo, print_status, NULL,
+ check_cancelled, NULL);
+done:
+ free(worktree_path);
+ return error;
}
-#endif