From 0f76863d9b6a260812bcdaae0bccef8e8fb1cb99 Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Wed, 23 May 2018 23:36:24 +0100 Subject: [PATCH 1/3] add: git-ignore -p (private to repo) --- Commands.md | 1 + bin/git-ignore | 16 ++++++++++++++++ etc/bash_completion.sh | 4 ++-- etc/git-extras-completion.zsh | 3 ++- man/git-ignore.1 | 6 ++++++ man/git-ignore.html | 4 ++++ man/git-ignore.md | 4 ++++ 7 files changed, 35 insertions(+), 3 deletions(-) diff --git a/Commands.md b/Commands.md index c511de1..6bee468 100644 --- a/Commands.md +++ b/Commands.md @@ -602,6 +602,7 @@ To show just the global or just the local file's contents, you can use the follo * `-g` or `--global` to show just the global file * `-l` or `--local` to show just the local file +* `-p` or `--private` to show just the repository's file ```bash $ git ignore -g diff --git a/bin/git-ignore b/bin/git-ignore index 85bd5e4..11a59d4 100755 --- a/bin/git-ignore +++ b/bin/git-ignore @@ -35,6 +35,16 @@ function add_local { add_patterns .gitignore "$@" } +function show_private { + cd "$(git root)" + show_contents Private .git/info/exclude +} + +function add_private { + cd "$(git root)" + add_patterns .git/info/exclude "$@" +} + function add_patterns { echo "Adding pattern(s) to: $1" local file="${1/#~/$HOME}" @@ -48,6 +58,8 @@ if test $# -eq 0; then show_global echo "---------------------------------" show_local + echo "---------------------------------" + show_private else case "$1" in -l|--local) @@ -58,6 +70,10 @@ else test $# -gt 1 && add_global "${@:2}" && echo show_global ;; + -p|--private) + test $# -gt 1 && add_private "${@:2}" && echo + show_private + ;; *) add_local "$@" ;; diff --git a/etc/bash_completion.sh b/etc/bash_completion.sh index a28d3f3..d720ab4 100644 --- a/etc/bash_completion.sh +++ b/etc/bash_completion.sh @@ -94,11 +94,11 @@ _git_graft(){ _git_ignore(){ case "$cur" in --*) - __gitcomp "--global --local" + __gitcomp "--global --local --private" return ;; -*) - __gitcomp "--global --local -g -l" + __gitcomp "--global --local --private -g -l -p" return ;; esac diff --git a/etc/git-extras-completion.zsh b/etc/git-extras-completion.zsh index 8272ff7..a5f5c0e 100644 --- a/etc/git-extras-completion.zsh +++ b/etc/git-extras-completion.zsh @@ -329,7 +329,8 @@ _git-guilt() { _git-ignore() { _arguments -C \ '(--local -l)'{--local,-l}'[show local gitignore]' \ - '(--global -g)'{--global,-g}'[show global gitignore]' + '(--global -g)'{--global,-g}'[show global gitignore]' \ + '(--private -p)'{--private,-p}'[show repo gitignore]' } diff --git a/man/git-ignore.1 b/man/git-ignore.1 index 63006d9..f1bf4ad 100644 --- a/man/git-ignore.1 +++ b/man/git-ignore.1 @@ -28,6 +28,12 @@ Sets the context to the \.gitignore file in the current working directory\. (def Sets the context to the global gitignore file for the current user\. . .P +\-p, \-\-private +. +.P +Sets the context to the private exclude file for the repository (\fB\.git/info/exclude\fR)\. +. +.P . .P diff --git a/man/git-ignore.html b/man/git-ignore.html index dec1139..951a23f 100644 --- a/man/git-ignore.html +++ b/man/git-ignore.html @@ -94,6 +94,10 @@

Sets the context to the global gitignore file for the current user.

+

-p, --private

+ +

Sets the context to the private exclude file for the repository (.git/info/exclude).

+

<pattern>

A space delimited list of patterns to append to the file in context.

diff --git a/man/git-ignore.md b/man/git-ignore.md index 968e822..e37f515 100644 --- a/man/git-ignore.md +++ b/man/git-ignore.md @@ -21,6 +21,10 @@ Adds the given _pattern_s to a .gitignore file if it doesn't already exist. Sets the context to the global gitignore file for the current user. + -p, --private + + Sets the context to the private exclude file for the repository (`.git/info/exclude`). + <pattern> A space delimited list of patterns to append to the file in context. From 691d640b2d0289945dae8fc8ba22cd0c941e2b10 Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Fri, 25 May 2018 10:12:26 +0100 Subject: [PATCH 2/3] Ensure info dir exists --- bin/git-ignore | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/git-ignore b/bin/git-ignore index 11a59d4..c478b0d 100755 --- a/bin/git-ignore +++ b/bin/git-ignore @@ -42,6 +42,7 @@ function show_private { function add_private { cd "$(git root)" + mkdir -p .git/info add_patterns .git/info/exclude "$@" } From f30005acfdad35915cfe13241f12c77ac870428b Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Fri, 25 May 2018 11:16:14 +0100 Subject: [PATCH 3/3] optimisation of mkdir --- bin/git-ignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/git-ignore b/bin/git-ignore index c478b0d..7c4d7ec 100755 --- a/bin/git-ignore +++ b/bin/git-ignore @@ -42,7 +42,7 @@ function show_private { function add_private { cd "$(git root)" - mkdir -p .git/info + test -d .git/info || mkdir -p .git/info add_patterns .git/info/exclude "$@" }