document diff command and make the repo path optional
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
diff --git a/got/got.1 b/got/got.1
index 971ecdd..d36fc50 100644
--- a/got/got.1
+++ b/got/got.1
@@ -93,6 +93,12 @@ commits.
If the
.Ar repository path
is omitted, use the current working directory.
+.It Cm diff [ Ar repository-path ] Ar object1 Ar object2
+Display the differences between two objects in the repository.
+Both objects must be of the same type (blobs, trees, or commits).
+If the
+.Ar repository path
+is omitted, use the current working directory.
.El
.Sh EXIT STATUS
.Ex -std got
diff --git a/got/got.c b/got/got.c
index dfaf97f..cb7b07e 100644
--- a/got/got.c
+++ b/got/got.c
@@ -496,14 +496,6 @@ cmd_log(int argc, char *argv[])
return error;
}
-__dead void
-usage_diff(void)
-{
- fprintf(stderr, "usage: %s diff repository-path object1 object2\n",
- getprogname());
- exit(1);
-}
-
static const struct got_error *
diff_blobs(struct got_object *obj1, struct got_object *obj2,
struct got_repository *repo)
@@ -586,6 +578,14 @@ done:
}
+__dead void
+usage_diff(void)
+{
+ fprintf(stderr, "usage: %s diff [repository-path] object1 object2\n",
+ getprogname());
+ exit(1);
+}
+
const struct got_error *
cmd_diff(int argc, char *argv[])
{
@@ -615,6 +615,12 @@ cmd_diff(int argc, char *argv[])
if (argc == 0) {
usage_diff(); /* TODO show local worktree changes */
+ } else if (argc == 2) {
+ repo_path = getcwd(NULL, 0);
+ if (repo_path == NULL)
+ err(1, "getcwd");
+ obj_id_str1 = argv[0];
+ obj_id_str2 = argv[1];
} else if (argc == 3) {
repo_path = argv[0];
obj_id_str1 = argv[1];