From: Stefan Beller <sbeller@google.com>
To: gitster@pobox.com, jrnieder@gmail.com
Cc: git@vger.kernel.org, Stefan Beller <sbeller@google.com>
Subject: [PATCH v2] short status: improve reporting for submodule changes
Date: Thu, 16 Mar 2017 13:46:44 -0700 [thread overview]
Message-ID: <20170316204644.11616-1-sbeller@google.com> (raw)
In-Reply-To: <CAGZ79kZ7rWw=q6a2AomTw20DsU1h+7ou4i8A14a2bcg+asRwLA@mail.gmail.com>
While we already have a porcelain2 layer for git-status, that is accurate
for submodules, users still like the way they are are used to of
'status -s'.
As a submodule has more state than a file potentially, we need more letters
indicating these states, we'll go with lower 'm' and single '?' for now.
When there the recorded commit doesn't differ from the submodule HEAD
(which we still want to treat as "M", because that can be dealt with
in the superproject), we can have different types of change in the
submodule. The lower case 'm' indicates that there are changes to tracked
files in the submodule. It signals that the --recurse-submodules option
is needed for e.g. adding or committing these changes. The " ?" also
differentiates an untracked file in the submodule from a regular
untracked file.
While making these changes, we need to make sure to not break porcelain
level 1, which uses the same code as the short printing function.
Signed-off-by: Stefan Beller <sbeller@google.com>
---
Documentation/git-status.txt | 8 ++++++++
t/t7506-status-submodule.sh | 24 ++++++++++++++++++++++++
wt-status.c | 15 +++++++++++++--
wt-status.h | 1 +
4 files changed, 46 insertions(+), 2 deletions(-)
diff --git a/Documentation/git-status.txt b/Documentation/git-status.txt
index ba873657cf..b182b16c48 100644
--- a/Documentation/git-status.txt
+++ b/Documentation/git-status.txt
@@ -181,6 +181,12 @@ in which case `XY` are `!!`.
! ! ignored
-------------------------------------------------
+Submodules have more state to it, such that it reports instead:
+ M the submodule has a different HEAD than recorded
+ m the submodule has modified content
+ ? the submodule has untracked files
+
+
If -b is used the short-format status is preceded by a line
## branchname tracking info
@@ -210,6 +216,8 @@ field from the first filename). Third, filenames containing special
characters are not specially formatted; no quoting or
backslash-escaping is performed.
+Any submodule changes are reported as modified `M` instead of `m` or single `?`.
+
Porcelain Format Version 2
~~~~~~~~~~~~~~~~~~~~~~~~~~
diff --git a/t/t7506-status-submodule.sh b/t/t7506-status-submodule.sh
index d31b34da83..98dff01947 100755
--- a/t/t7506-status-submodule.sh
+++ b/t/t7506-status-submodule.sh
@@ -50,6 +50,15 @@ test_expect_success 'status with modified file in submodule (porcelain)' '
EOF
'
+test_expect_success 'status with modified file in submodule (short)' '
+ (cd sub && git reset --hard) &&
+ echo "changed" >sub/foo &&
+ git status --short >output &&
+ diff output - <<-\EOF
+ m sub
+ EOF
+'
+
test_expect_success 'status with added file in submodule' '
(cd sub && git reset --hard && echo >foo && git add foo) &&
git status >output &&
@@ -64,6 +73,14 @@ test_expect_success 'status with added file in submodule (porcelain)' '
EOF
'
+test_expect_success 'status with added file in submodule (short)' '
+ (cd sub && git reset --hard && echo >foo && git add foo) &&
+ git status --short >output &&
+ diff output - <<-\EOF
+ m sub
+ EOF
+'
+
test_expect_success 'status with untracked file in submodule' '
(cd sub && git reset --hard) &&
echo "content" >sub/new-file &&
@@ -83,6 +100,13 @@ test_expect_success 'status with untracked file in submodule (porcelain)' '
EOF
'
+test_expect_success 'status with untracked file in submodule (short)' '
+ git status --short >output &&
+ diff output - <<-\EOF
+ ? sub
+ EOF
+'
+
test_expect_success 'status with added and untracked file in submodule' '
(cd sub && git reset --hard && echo >foo && git add foo) &&
echo "content" >sub/new-file &&
diff --git a/wt-status.c b/wt-status.c
index a52d342695..080d97f272 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -1664,9 +1664,19 @@ static void wt_shortstatus_status(struct string_list_item *it,
color_fprintf(s->fp, color(WT_STATUS_UPDATED, s), "%c", d->index_status);
else
putchar(' ');
- if (d->worktree_status)
+ if (d->worktree_status) {
+ if (!s->submodule_porcelain1 &&
+ (d->dirty_submodule || d->new_submodule_commits)) {
+ /* It is a submodule, and we're not in plumbing mode. */
+ if (d->new_submodule_commits)
+ d->worktree_status = 'M';
+ else if (d->dirty_submodule & DIRTY_SUBMODULE_MODIFIED)
+ d->worktree_status = 'm';
+ else if (d->dirty_submodule & DIRTY_SUBMODULE_UNTRACKED)
+ d->worktree_status = '?';
+ }
color_fprintf(s->fp, color(WT_STATUS_CHANGED, s), "%c", d->worktree_status);
- else
+ } else
putchar(' ');
putchar(' ');
if (s->null_termination) {
@@ -1811,6 +1821,7 @@ static void wt_porcelain_print(struct wt_status *s)
s->relative_paths = 0;
s->prefix = NULL;
s->no_gettext = 1;
+ s->submodule_porcelain1 = 1;
wt_shortstatus_print(s);
}
diff --git a/wt-status.h b/wt-status.h
index 54fec77032..620e4d2ae4 100644
--- a/wt-status.h
+++ b/wt-status.h
@@ -70,6 +70,7 @@ struct wt_status {
int display_comment_prefix;
int relative_paths;
int submodule_summary;
+ int submodule_porcelain1;
int show_ignored_files;
enum untracked_status_type show_untracked_files;
const char *ignore_submodule_arg;
--
2.12.0.269.g1a05a5734c.dirty
next prev parent reply other threads:[~2017-03-16 20:46 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-16 0:33 [RFC PATCH] short status: improve reporting for submodule changes Stefan Beller
2017-03-16 1:31 ` Junio C Hamano
2017-03-16 5:16 ` Stefan Beller
2017-03-16 20:46 ` Stefan Beller [this message]
2017-03-16 22:19 ` [PATCH v2] " Jonathan Nieder
2017-03-16 22:42 ` Stefan Beller
2017-03-16 22:53 ` Jonathan Nieder
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170316204644.11616-1-sbeller@google.com \
--to=sbeller@google.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jrnieder@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).