Commit 3f8b7d6a05bca2370be722ebddb8b2418a30ffd2

Stefan Sperling 2018-04-01T20:03:30

document diff command and make the repo path optional

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];