Skip to contentSkip to conversation

request-pull: improve error message for invalid revision args

PATCH In review Dirk Wallenstein 2 participants 3 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 request-pull: improve error message for invalid revision args

When an invalid revision is specified, the error message is:

fatal: Needed a single revision

This is misleading because, you might think there is something wrong with the command line as a whole.

Now the user gets a more meaningful error message, showing the invalid revision.

---

Notes:
I assume, it is not worth the trouble to even try to change the message from rev-parse for this. People might parse the messages, which is probably why this message still exists.

 git-request-pull.sh | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
git-request-pull.sh +12 -2
index d566015..f38f0f9 100755
@@ -51,8 +51,18 @@ fi
 tag_name=$(git describe --exact "$head^0" 2>/dev/null)
 
 test -n "$base" && test -n "$url" || usage
-baserev=$(git rev-parse --verify "$base"^0) &&
-headrev=$(git rev-parse --verify "$head"^0) || exit
+
+baserev=$(git rev-parse --verify "$base"^0 2>/dev/null)
+if test -z "$baserev"
+then
+    die "fatal: Not a valid revision: $base"
+fi
+
+headrev=$(git rev-parse --verify "$head"^0 2>/dev/null)
+if test -z "$headrev"
+then
+    die "fatal: Not a valid revision: $head"
+fi
 
 merge_base=$(git merge-base $baserev $headrev) ||
 die "fatal: No commits in common between $base and $head"
Signature · 1 line
1.8.3.2.51.g8658a4c
#1 lore raw
Quoted 10 lines · Dirk Wallenstein

When an invalid revision is specified, the error message is:

fatal: Needed a single revision

This is misleading because, you might think there is something wrong with the command line as a whole.

Now the user gets a more meaningful error message, showing the invalid revision.

Quoted 7 lines

---

Notes:
I assume, it is not worth the trouble to even try to change the message from rev-parse for this. People might parse the messages, which is probably why this message still exists.

You are right---such a change will break existing scripts, so it is not just "not worth the trouble" but is actively wrong to change the error message.

Quoted 8 lines
 git-request-pull.sh | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
git-request-pull.sh +0 -0
index d566015..f38f0f9 100755

git-request-pull.sh fi · line 55

Quoted 7 lines
git-request-pull.sh +2 -2
@@ -51,8 +51,18 @@ fi
 tag_name=$(git describe --exact "$head^0" 2>/dev/null)
 
 test -n "$base" && test -n "$url" || usage
-baserev=$(git rev-parse --verify "$base"^0) &&
-headrev=$(git rev-parse --verify "$head"^0) || exit
+
+baserev=$(git rev-parse --verify "$base"^0 2>/dev/null)

Use "--quiet" instead?

Quoted 13 lines
git-request-pull.sh +10 -0
+if test -z "$baserev"
+then
+    die "fatal: Not a valid revision: $base"
+fi
+
+headrev=$(git rev-parse --verify "$head"^0 2>/dev/null)
+if test -z "$headrev"
+then
+    die "fatal: Not a valid revision: $head"
+fi
 
 merge_base=$(git merge-base $baserev $headrev) ||
 die "fatal: No commits in common between $base and $head"
#2 lore raw

PATCH v2 1/1 request-pull: improve error message for invalid revision args

Currently, when an invalid revision is specified, the error message is:

fatal: Needed a single revision

This is misleading because, you might think there is something wrong with the command line as a whole.

Now the user gets a more meaningful error message, showing the invalid revision.

---

Quoted 4 lines · Junio C Hamano
Quoted 1 line · Dirk Wallenstein

+baserev=$(git rev-parse --verify "$base"^0 2>/dev/null)

Use "--quiet" instead?

Oh, of course.

 git-request-pull.sh | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
git-request-pull.sh +12 -2
index d566015..ebf1269 100755
@@ -51,8 +51,18 @@ fi
 tag_name=$(git describe --exact "$head^0" 2>/dev/null)
 
 test -n "$base" && test -n "$url" || usage
-baserev=$(git rev-parse --verify "$base"^0) &&
-headrev=$(git rev-parse --verify "$head"^0) || exit
+
+baserev=$(git rev-parse --verify --quiet "$base"^0)
+if test -z "$baserev"
+then
+    die "fatal: Not a valid revision: $base"
+fi
+
+headrev=$(git rev-parse --verify --quiet "$head"^0)
+if test -z "$headrev"
+then
+    die "fatal: Not a valid revision: $head"
+fi
 
 merge_base=$(git merge-base $baserev $headrev) ||
 die "fatal: No commits in common between $base and $head"
Signature · 1 line
1.8.3.3.2.g85103ba