mirror of
https://github.com/git/git
synced 2024-08-27 19:49:21 +00:00
![Fredrik Kuivinen](/assets/img/avatar_default.png)
There were some problems with the usage message clean-up patch series. I hadn't realised that subdirectory aware scripts can't source git-sh-setup. I propose that we change this and let the scripts which are subdirectory aware set a variable, SUBDIRECTORY_OK, before they source git-sh-setup. The scripts will also set USAGE and possibly LONG_USAGE before they source git-sh-setup. If LONG_USAGE isn't set it defaults to USAGE. If we go this way it's easy to catch --help in git-sh-setup, print the (long) usage message to stdout and exit cleanly. git-sh-setup can define a 'usage' shell function which can be called by the scripts to print the short usage string to stderr and exit non-cleanly. It will also be easy to change $0 to basename $0 or something else, if would like to do that sometime in the future. What follows is a patch to convert a couple of the commands to this style. If it's ok with everyone to do it this way I will convert the rest of the scripts too. [jc: thrown in to proposed updates queue for comments.] Signed-off-by: Junio C Hamano <junkio@cox.net>
116 lines
1.9 KiB
Bash
Executable file
116 lines
1.9 KiB
Bash
Executable file
#!/bin/sh
|
|
#
|
|
# Copyright (c) 2005 Linus Torvalds
|
|
#
|
|
|
|
USAGE=''
|
|
SUBDIRECTORY_OK='Yes'
|
|
|
|
. git-sh-setup
|
|
|
|
if [ "$#" != "0" ]
|
|
then
|
|
usage
|
|
fi
|
|
|
|
report () {
|
|
header="#
|
|
# $1:
|
|
# ($2)
|
|
#
|
|
"
|
|
trailer=""
|
|
while read status name newname
|
|
do
|
|
printf '%s' "$header"
|
|
header=""
|
|
trailer="#
|
|
"
|
|
case "$status" in
|
|
M ) echo "# modified: $name";;
|
|
D*) echo "# deleted: $name";;
|
|
T ) echo "# typechange: $name";;
|
|
C*) echo "# copied: $name -> $newname";;
|
|
R*) echo "# renamed: $name -> $newname";;
|
|
A*) echo "# new file: $name";;
|
|
U ) echo "# unmerged: $name";;
|
|
esac
|
|
done
|
|
printf '%s' "$trailer"
|
|
[ "$header" ]
|
|
}
|
|
|
|
branch=$(GIT_DIR="$GIT_DIR" git-symbolic-ref HEAD)
|
|
case "$branch" in
|
|
refs/heads/master) ;;
|
|
*) echo "# On branch $branch" ;;
|
|
esac
|
|
|
|
git-update-index -q --unmerged --refresh || exit
|
|
|
|
if GIT_DIR="$GIT_DIR" git-rev-parse --verify HEAD >/dev/null 2>&1
|
|
then
|
|
git-diff-index -M --cached --name-status --diff-filter=MDTCRA HEAD |
|
|
sed -e '
|
|
s/\\/\\\\/g
|
|
s/ /\\ /g
|
|
' |
|
|
report "Updated but not checked in" "will commit"
|
|
|
|
committable="$?"
|
|
else
|
|
echo '#
|
|
# Initial commit
|
|
#'
|
|
git-ls-files |
|
|
sed -e '
|
|
s/\\/\\\\/g
|
|
s/ /\\ /g
|
|
s/^/A /
|
|
' |
|
|
report "Updated but not checked in" "will commit"
|
|
|
|
committable="$?"
|
|
fi
|
|
|
|
git-diff-files --name-status |
|
|
sed -e '
|
|
s/\\/\\\\/g
|
|
s/ /\\ /g
|
|
' |
|
|
report "Changed but not updated" "use git-update-index to mark for commit"
|
|
|
|
|
|
if test -f "$GIT_DIR/info/exclude"
|
|
then
|
|
git-ls-files -z --others \
|
|
--exclude-from="$GIT_DIR/info/exclude" \
|
|
--exclude-per-directory=.gitignore
|
|
else
|
|
git-ls-files -z --others \
|
|
--exclude-per-directory=.gitignore
|
|
fi |
|
|
perl -e '$/ = "\0";
|
|
my $shown = 0;
|
|
while (<>) {
|
|
chomp;
|
|
s|\\|\\\\|g;
|
|
s|\t|\\t|g;
|
|
s|\n|\\n|g;
|
|
s/^/# /;
|
|
if (!$shown) {
|
|
print "#\n# Untracked files:\n";
|
|
print "# (use \"git add\" to add to commit)\n#\n";
|
|
$shown = 1;
|
|
}
|
|
print "$_\n";
|
|
}
|
|
'
|
|
|
|
case "$committable" in
|
|
0)
|
|
echo "nothing to commit"
|
|
exit 1
|
|
esac
|
|
exit 0
|