@matheusbsbs / matheus-bagliano / commits / 9c7c27eeab
Fork 0

update-index -h: show usage even with corrupt index

When trying to fix up a corrupt repository, one might prefer that "update-index -h" print an accurate usage message and exit rather than reading the repository and complaining about the corruption. [jn: with rewritten log message and tests] Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Oct 22, 2010 at 01:51 UTC 9c7c27eeab73b4c90cf36c6aa06ba6b8b9777629
2 files changed +35
builtin/update-index.c
+3
@@ -589,6 +589,9 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
589 int lock_error = 0;
590 struct lock_file *lock_file;
591
592 + if (argc == 2 && !strcmp(argv[1], "-h"))
593 + usage(update_index_usage);
594 +
595 git_config(git_default_config, NULL);
596
597 /* We can't free this memory, it becomes part of a linked list parsed atexit() */
t/t2107-update-index-basic.sh new
+32
@@ -0,0 +1,32 @@
1 +#!/bin/sh
2 +
3 +test_description='basic update-index tests
4 +
5 +Tests for command-line parsing and basic operation.
6 +'
7 +
8 +. ./test-lib.sh
9 +
10 +test_expect_success 'update-index --nonsense fails' '
11 + test_must_fail git update-index --nonsense 2>msg &&
12 + cat msg &&
13 + test -s msg
14 +'
15 +
16 +test_expect_failure 'update-index --nonsense dumps usage' '
17 + test_expect_code 129 git update-index --nonsense 2>err &&
18 + grep "[Uu]sage: git update-index" err
19 +'
20 +
21 +test_expect_success 'update-index -h with corrupt index' '
22 + mkdir broken &&
23 + (
24 + cd broken &&
25 + git init &&
26 + >.git/index &&
27 + test_expect_code 129 git update-index -h >usage 2>&1
28 + ) &&
29 + grep "[Uu]sage: git update-index" broken/usage
30 +'
31 +
32 +test_done