Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The bits of Git plumbing you need are <a href="http://www.kernel.org/pub/software/scm/git/docs/git-diff-index.html" rel="nofollow noreferrer"><code>diff-index</code></a>, <a href="http://www.kernel.org/pub/software/scm/git/docs/git-rev-parse.html" rel="nofollow noreferrer"><code>rev-parse --verify</code></a> and maybe <a href="http://www.kernel.org/pub/software/scm/git/docs/git-rev-parse.html" rel="nofollow noreferrer"><code>rev-parse --show-cdup</code></a> with <a href="http://www.kernel.org/pub/software/scm/git/docs/git-ls-files.html" rel="nofollow noreferrer"><code>ls-files --others</code></a>.</p> <p>The following shell program uses those Git plumbing commands, has adjustable untracked/ignored handling, and is fairly careful about all the possible error cases.</p> <pre><code>#!/bin/sh # warn-unclean: print a warning if the working tree and index are not clean # For utmost strictness, set check_untracked=yes and check_ignored=yes. # When both are 'yes', verify that working tree and index are identical to HEAD. # When only check_untracked is yes, extra ignored files are allowed. # When neither is yes, extra untracked files and ignored files are allowed. check_untracked=yes check_ignored=yes warn() { echo 'Warning: '"$*" \ 'This output may not be reproducible.' } # Compare HEAD to index and/or working tree versions of tracked files git diff-index --quiet HEAD case $? in 0) if test "$check_untracked" != yes; then clean=yes else # Still need to check for untracked files or_ignored='' exclude=--exclude-standard if test "$check_ignored" = yes; then or_ignored=' or ignored' exclude='' fi ( # Move to top level of working tree if up="$(git rev-parse --show-cdup)"; then test -n "$up" &amp;&amp; cd "$up" else echo 'error running "git rev-parse --show-cdup"' exit 129 fi # Check for untracked files git ls-files --others $exclude --error-unmatch . &gt;/dev/null 2&gt;&amp;1 case $? in 0) # some untracked/ignored file is present warn 'some untracked'"$or_ignored"' file is present.' exit 1 ;; 1) # no untracked files exit 0 ;; *) echo 'error running "git diff-index"!' exit 129 ;; esac ) case $? in 0) clean=yes ;; 1) clean=no ;; *) exit $? ;; esac fi test "$clean" = yes &amp;&amp; if c="$(git rev-parse --verify HEAD)"; then echo 'Current commit: '"$c" else echo 'error running "git rev-parse --verify"!' fi ;; 1) warn 'some tracked file has an uncommitted change.' ;; *) echo 'error running "git diff-index"!' exit 129 ;; esac </code></pre> <p>You might sprinkle in some more <code>exit</code>s if you want its exit code to be meaningful in all cases.</p> <p>If you do not care for all the error handling or the untracked/ignored handling, then something short might suffice:</p> <pre><code>if git diff-index --quiet; then printf 'Current commit: %s\n' "$(git rev-parse --verify HEAD) else echo 'Warning: …' fi </code></pre> <p>You can also check for untracked files (which could be tweaked for ignored etc) in a terse way, without error handling:</p> <pre><code>git ls-files --others --exclude-standard --error-unmatch \ "./$(git rev-parse --show-cdup)" &gt;/dev/null 2&gt;&amp;1 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload