Skip to content
  • Stefan Beller's avatar
    short status: improve reporting for submodule changes · dd6962dd
    Stefan Beller authored and Junio C Hamano's avatar Junio C Hamano committed
    If I add an untracked file to a submodule or modify a tracked file,
    currently "git status --short" treats the change in the same way as
    changes to the current HEAD of the submodule:
    
            $ git clone --quiet --recurse-submodules https://gerrit.googlesource.com/gerrit
    
    
            $ echo hello >gerrit/plugins/replication/stray-file
            $ sed -i -e 's/.*//' gerrit/plugins/replication/.mailmap
            $ git -C gerrit status --short
             M plugins/replication
    
    This is by analogy with ordinary files, where "M" represents a change
    that has not been added yet to the index.  But this change cannot be
    added to the index without entering the submodule, "git add"-ing it,
    and running "git commit", so the analogy is counterproductive.
    
    Introduce new status letters " ?" and " m" for this.  These are similar
    to the existing "??" and " M" but mean that the submodule (not the
    parent project) has new untracked files and modified files, respectively.
    The user can use "git add" and "git commit" from within the submodule to
    add them.
    
    Changes to the submodule's HEAD commit can be recorded in the index with
    a plain "git add -u" and are shown with " M", like today.
    
    To avoid excessive clutter, show at most one of " ?", " m", and " M" for
    the submodule.  They represent increasing levels of change --- the last
    one that applies is shown (e.g., " m" if there are both modified files
    and untracked files in the submodule, or " M" if the submodule's HEAD
    has been modified and it has untracked files).
    
    While making these changes, we need to make sure to not break porcelain
    level 1, which shares code with "status --short".  We only change
    "git status --short".
    
    Non-short "git status" and "git status --porcelain=2" already handle
    these cases by showing more detail:
    
            $ git -C gerrit status --porcelain=2
            1 .M S.MU 160000 160000 160000 305c864db28eb0c77c8499bc04c87de3f849cf3c 305c864db28eb0c77c8499bc04c87de3f849cf3c plugins/replication
            $ git -C gerrit status
    [...]
            modified:   plugins/replication (modified content, untracked content)
    
    Scripts caring about these distinctions should use --porcelain=2.
    
    Helped-by: default avatarJonathan Nieder <jrnieder@gmail.com>
    Signed-off-by: default avatarStefan Beller <sbeller@google.com>
    Reviewed-by: default avatarJonathan Nieder <jrnieder@gmail.com>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    dd6962dd