Browse Source

Merge branch 'py/submodule'

* py/submodule:
  builtin-status: Add tests for submodule summary
  builtin-status: submodule summary support
  git-submodule summary: --for-status option
maint
Junio C Hamano 17 years ago
parent
commit
3642617ee7
  1. 5
      Documentation/git-status.txt
  2. 16
      git-submodule.sh
  3. 13
      t/t7401-submodule-summary.sh
  4. 134
      t/t7502-status.sh
  5. 41
      wt-status.c

5
Documentation/git-status.txt

@ -52,6 +52,11 @@ If the config variable `status.relativePaths` is set to false, then all @@ -52,6 +52,11 @@ If the config variable `status.relativePaths` is set to false, then all
paths shown are relative to the repository root, not to the current
directory.

If `status.submodulesummary` is set to a non zero number or true (identical
to -1 or an unlimited number), the submodule summary will be enabled and a
summary of commits for modified submodules will be shown (see --summary-limit
option of linkgit:git-submodule[1]).

See Also
--------
linkgit:gitignore[5]

16
git-submodule.sh

@ -343,6 +343,7 @@ set_name_rev () { @@ -343,6 +343,7 @@ set_name_rev () {
#
cmd_summary() {
summary_limit=-1
for_status=

# parse $args after "submodule ... summary".
while test $# -ne 0
@ -351,6 +352,9 @@ cmd_summary() { @@ -351,6 +352,9 @@ cmd_summary() {
--cached)
cached="$1"
;;
--for-status)
for_status="$1"
;;
-n|--summary-limit)
if summary_limit=$(($2 + 0)) 2>/dev/null && test "$summary_limit" = "$2"
then
@ -398,7 +402,8 @@ cmd_summary() { @@ -398,7 +402,8 @@ cmd_summary() {
done
)

test -n "$modules" &&
test -z "$modules" && return

git diff-index $cached --raw $head -- $modules |
grep -e '^:160000' -e '^:[0-7]* 160000' |
cut -c2- |
@ -500,7 +505,14 @@ cmd_summary() { @@ -500,7 +505,14 @@ cmd_summary() {
echo
fi
echo
done
done |
if test -n "$for_status"; then
echo "# Modified submodules:"
echo "#"
sed -e 's|^|# |' -e 's|^# $|#|'
else
cat
fi
}
#
# List all submodules, prefixed with:

13
t/t7401-submodule-summary.sh

@ -192,4 +192,17 @@ test_expect_success 'given commit' " @@ -192,4 +192,17 @@ test_expect_success 'given commit' "
EOF
"

test_expect_success '--for-status' "
git submodule summary --for-status HEAD^ >actual &&
test_cmp actual - <<EOF
# Modified submodules:
#
# * sm1 $head6...0000000:
#
# * sm2 0000000...$head7 (2):
# > Add foo9
#
EOF
"

test_done

134
t/t7502-status.sh

@ -149,4 +149,138 @@ test_expect_success 'status of partial commit excluding new file in index' ' @@ -149,4 +149,138 @@ test_expect_success 'status of partial commit excluding new file in index' '
test_cmp expect output
'

test_expect_success 'setup status submodule summary' '
test_create_repo sm && (
cd sm &&
>foo &&
git add foo &&
git commit -m "Add foo"
) &&
git add sm
'

cat >expect <<EOF
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: dir2/added
# new file: sm
#
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
#
# modified: dir1/modified
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# dir1/untracked
# dir2/modified
# dir2/untracked
# expect
# output
# untracked
EOF
test_expect_success 'status submodule summary is disabled by default' '
git status >output &&
test_cmp expect output
'

head=$(cd sm && git rev-parse --short=7 --verify HEAD)

cat >expect <<EOF
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: dir2/added
# new file: sm
#
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
#
# modified: dir1/modified
#
# Modified submodules:
#
# * sm 0000000...$head (1):
# > Add foo
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# dir1/untracked
# dir2/modified
# dir2/untracked
# expect
# output
# untracked
EOF
test_expect_success 'status submodule summary' '
git config status.submodulesummary 10 &&
git status >output &&
test_cmp expect output
'


cat >expect <<EOF
# On branch master
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
#
# modified: dir1/modified
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# dir1/untracked
# dir2/modified
# dir2/untracked
# expect
# output
# untracked
no changes added to commit (use "git add" and/or "git commit -a")
EOF
test_expect_success 'status submodule summary (clean submodule)' '
git commit -m "commit submodule" &&
git config status.submodulesummary 10 &&
test_must_fail git status >output &&
test_cmp expect output
'

cat >expect <<EOF
# On branch master
# Changes to be committed:
# (use "git reset HEAD^1 <file>..." to unstage)
#
# new file: dir2/added
# new file: sm
#
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
#
# modified: dir1/modified
#
# Modified submodules:
#
# * sm 0000000...$head (1):
# > Add foo
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# dir1/untracked
# dir2/modified
# dir2/untracked
# expect
# output
# untracked
EOF
test_expect_success 'status submodule summary (--amend)' '
git config status.submodulesummary 10 &&
git status --amend >output &&
test_cmp expect output
'

test_done

41
wt-status.c

@ -8,9 +8,11 @@ @@ -8,9 +8,11 @@
#include "revision.h"
#include "diffcore.h"
#include "quote.h"
#include "run-command.h"

int wt_status_relative_paths = 1;
int wt_status_use_color = -1;
int wt_status_submodule_summary;
static char wt_status_colors[][COLOR_MAXLEN] = {
"", /* WT_STATUS_HEADER: normal */
"\033[32m", /* WT_STATUS_UPDATED: green */
@ -220,6 +222,36 @@ static void wt_status_print_changed(struct wt_status *s) @@ -220,6 +222,36 @@ static void wt_status_print_changed(struct wt_status *s)
run_diff_files(&rev, 0);
}

static void wt_status_print_submodule_summary(struct wt_status *s)
{
struct child_process sm_summary;
char summary_limit[64];
char index[PATH_MAX];
const char *env[] = { index, NULL };
const char *argv[] = {
"submodule",
"summary",
"--cached",
"--for-status",
"--summary-limit",
summary_limit,
s->amend ? "HEAD^" : "HEAD",
NULL
};

sprintf(summary_limit, "%d", wt_status_submodule_summary);
snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", s->index_file);

memset(&sm_summary, 0, sizeof(sm_summary));
sm_summary.argv = argv;
sm_summary.env = env;
sm_summary.git_cmd = 1;
sm_summary.no_stdin = 1;
fflush(s->fp);
sm_summary.out = dup(fileno(s->fp)); /* run_command closes it */
run_command(&sm_summary);
}

static void wt_status_print_untracked(struct wt_status *s)
{
struct dir_struct dir;
@ -308,6 +340,8 @@ void wt_status_print(struct wt_status *s) @@ -308,6 +340,8 @@ void wt_status_print(struct wt_status *s)
}

wt_status_print_changed(s);
if (wt_status_submodule_summary)
wt_status_print_submodule_summary(s);
wt_status_print_untracked(s);

if (s->verbose && !s->is_initial)
@ -330,6 +364,13 @@ void wt_status_print(struct wt_status *s) @@ -330,6 +364,13 @@ void wt_status_print(struct wt_status *s)

int git_status_config(const char *k, const char *v)
{
if (!strcmp(k, "status.submodulesummary")) {
int is_bool;
wt_status_submodule_summary = git_config_bool_or_int(k, v, &is_bool);
if (is_bool && wt_status_submodule_summary)
wt_status_submodule_summary = -1;
return 0;
}
if (!strcmp(k, "status.color") || !strcmp(k, "color.status")) {
wt_status_use_color = git_config_colorbool(k, v, -1);
return 0;

Loading…
Cancel
Save