Skip to contentSkip to conversation

hook for git status

PATCH New Suvorov Ivan 1 participant 1 message Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hook for git status

From 0f435feee87dc96b2e4890a5a5de7b1d0c0befe1 Mon Sep 17 00:00:00 2001
From: magisterRab <[email protected]>
Date: Tue, 1 Apr 2014 17:02:10 +0400
Subject: [PATCH] hook for git status

---
hook for git status allows you to display additional fields when you run git status. For example, for a hook with a content of

STATUS_FILE=$1
NEW_SCOPE=$2

cat > "$STATUS_FILE" <<EOF
Binary files
add --binary
lib.lib
lib.a
lib.o
$NEW_SCOPE
Other files
add --other
dll.lib
dll.a
dll.o
EOF

here's how it will look conclusion

Binary files:
(use "git add --binary <file>..." to include in what will be committed)

lib.a
lib.lib
lib.o

Other files:
(use "git add --other <file>..." to include in what will be committed)

dll.a
dll.lib
dll.o

 Documentation/git-status.txt | 10 +++
 Documentation/githooks.txt | 9 +++
 builtin/commit.c | 7 +++
 t/t7513-status-hook.sh | 137 +++++++++++++++++++++++++++++++++++++++++
 templates/hooks--status.sample | 36 +++++++++++
 wt-status.c | 88 ++++++++++++++++++++++++++
 wt-status.h | 1 +
 7 files changed, 288 insertions(+)
 create mode 100644 t/t7513-status-hook.sh
 create mode 100755 templates/hooks--status.sample
Documentation/git-status.txt +10 -0
index def635f..6c81323 100644
@@ -94,6 +94,10 @@ configuration variable documented in linkgit:git-config[1].
 respectively.
 
 
+--no-run-hook::
+ This option bypasses the status hooks.
+ See also linkgit:githooks[5].
+ 
 OUTPUT
 ------
 The output from this command is designed to be used as a commit
@@ -218,9 +222,15 @@ ignored submodules you can either use the --ignore-submodules=dirty command
 line option or the 'git submodule summary' command, which shows a similar
 output but does not honor these settings.
 
+HOOKS
+-----
+This command can run `status` hooks. See linkgit:githooks[5] for more
+information.
+
 SEE ALSO
 --------
 linkgit:gitignore[5]
+linkgit:githooks[5]
 
 GIT
 ---
Documentation/githooks.txt +9 -0
index d954bf6..e3e3206 100644
@@ -381,6 +381,15 @@ rebase::
 The commits are guaranteed to be listed in the order that they were
 processed by rebase.
 
+status
+~~~~~~~~~~~
+
+This hook is invoked by 'git status', and can be bypassed
+with `--no-run-hook` option. Exiting with non-zero status from this script
+causes the 'git status' to abort.
+
+The default 'status' hook, when enabled, adds to the output 
+of the command 'git status' several files names.
 
 GIT
 ---
builtin/commit.c +7 -0
index 9cfef6c..16c430f 100644
@@ -122,6 +122,7 @@ static enum commit_whence whence;
 static int sequencer_in_use;
 static int use_editor = 1, include_status = 1;
 static int show_ignored_in_status, have_option_m;
+static int no_run_hook = 0;
 static const char *only_include_assumed;
 static struct strbuf message = STRBUF_INIT;
 
@@ -1276,6 +1277,8 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 N_("ignore changes to submodules, optional when: all, dirty, untracked. (Default: all)"),
 PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
 OPT_COLUMN(0, "column", &s.colopts, N_("list untracked files in columns")),
+ OPT_BOOL(0, "no-run-hook", &no_run_hook,
+ N_("bypass status hook")),
 OPT_END(),
 };
 
@@ -1296,6 +1299,10 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 PATHSPEC_PREFER_FULL,
 prefix, argv);
 
+ if (no_run_hook)
+ s.run_hook = 0;
+ else
+ s.run_hook = 1;
 read_cache_preload(&s.pathspec);
 refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, &s.pathspec, NULL, NULL);
 
t/t7513-status-hook.sh new file +137 -0

137 lines not on this page · raw message

templates/hooks--status.sample new file +36 -0
new file mode 100755
index 0000000..8739b44
@@ -0,0 +1,36 @@
+#!/bin/sh
+#
+# An example hook script to verify what is about to be status.
+# Called by "git status" with no arguments. The hook should
+# exit with non-zero status after issuing an appropriate message if
+# it wants to stop the status.
+#
+# To enable this hook, rename this file to "status".
+#
+# This hook is called with the following parameters:
+#
+# $1 -- Name and path of the file, from which it will take additional information for hook status
+# $2 -- line separating the blocks of information
+#
+# Information in the file must be contained in the blocks, the blocks
+# must be separated by a line separating. The first line of the block
+# must contain the type of files in the block, the second line should
+# contain a command to include in what will be committed, continue
+# until the end of the block or file files names, one file name per line.
+
+STATUS_FILE=$1
+NEW_SCOPE=$2
+
+cat > "$STATUS_FILE" <<EOF
+Binary files
+add --binary
+lib.lib
+lib.a
+lib.o
+$NEW_SCOPE
+Other files
+add --other
+dll.lib
+dll.a
+dll.o
+EOF
wt-status.c +88 -0

100 lines not on this page · raw message

wt-status.h +1 -0
index 283a9fe..ff94b22 100644
@@ -55,6 +55,7 @@ struct wt_status {
 int relative_paths;
 int submodule_summary;
 int show_ignored_files;
+ int run_hook;
 enum untracked_status_type show_untracked_files;
 const char *ignore_submodule_arg;
 char color_palette[WT_STATUS_MAXSLOT][COLOR_MAXLEN];
Signature · 1 line
1.8.5.2.msysgit.0