diff --git a/bin/git-ignore b/bin/git-ignore index bbbf216..dac8113 100755 --- a/bin/git-ignore +++ b/bin/git-ignore @@ -1,15 +1,50 @@ -#!/bin/sh +#!/bin/bash + +function show_contents { + test -f "$2" && echo "$1 gitignore: $2" && cat "$2" +} + +function show_global { + show_contents Global `git config --global core.excludesfile` +} + +function add_global { + add_patterns `git config --global core.excludesfile` "$@" +} + +function show_local { + show_contents Local .gitignore +} + +function add_local { + add_patterns .gitignore "$@" +} + +function add_patterns { + echo "Adding pattern(s) to: $1" + for pattern in "${@:2}"; do + echo "... adding '$pattern'" + (test -f "$1" && test "$pattern" && grep -q "$pattern" "$1") || echo "$pattern" >> "$1" + done +} if test $# -eq 0; then - test -f .gitignore && cat .gitignore - if test -f `git config --global core.excludesfile`; then - echo -e "\n# Global gitignore:\n" - cat `git config --global core.excludesfile` - fi + show_global + echo "---------------------------------" + show_local else - for pattern in $@; do - echo "... adding '$pattern' to .gitignore" - (test -f .gitignore && grep -q $pattern .gitignore) || echo $pattern >> .gitignore - done + case "$1" in + -l|--local) + test $# -gt 1 && add_local "${@:2}" && echo + show_local + ;; + -g|--global) + test $# -gt 1 && add_global "${@:2}" && echo + show_global + ;; + *) + add_local "$@" + ;; + esac fi diff --git a/man/git-ignore.1 b/man/git-ignore.1 index 986ea8b..e87bc44 100644 --- a/man/git-ignore.1 +++ b/man/git-ignore.1 @@ -1,53 +1,168 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "GIT\-IGNORE" "1" "March 2011" "" "Git Extras" +.TH "GIT\-IGNORE" "1" "July 2012" "" "" . .SH "NAME" \fBgit\-ignore\fR \- Add \.gitignore patterns . .SH "SYNOPSIS" -\fBgit\-ignore\fR [\|\.\|\.\|\.] +\fBgit\-ignore\fR [] [ []\.\.\.] . .SH "DESCRIPTION" -Adds the given _pattern_s to a gitignore file\. +Adds the given _pattern_s to a \.gitignore file if it doesn\'t already exist\. . .SH "OPTIONS" + . -.SH "EXAMPLES" -To lazy to open up \fI\.gitignore\fR? me too! simply pass some patterns: +.P +\-l, \-\-local . -.IP "" 4 +.P +Sets the context to the \.gitignore file in the current working directory\. (default) . -.nf - -$ git ignore build "*\.o" "*\.log" -\|\.\|\.\|\. added \'build\' - \|\.\|\.\|\. added \'*\.o\' -\|\.\|\.\|\. added \'*\.log\' +.P +\-g, \-\-global . -.fi +.P +Sets the context to the global gitignore file fol the current user\. +. +.P + +. +.P +A space delimited list of patterns to append to the file in context\. +. +.SS "PATTERN FORMAT" +Pattern format as described in the git manual +. +.IP "\(bu" 4 +A blank line matches no files, so it can serve as a separator for readability\. To append a blank line use empty quotes ""\. +. +.IP "\(bu" 4 +A line starting with # serves as a comment\. For example, "# This is a comment" +. +.IP "\(bu" 4 +An optional prefix ! which negates the pattern; any matching file excluded by a previous pattern will become included again\. If a negated pattern matches, this will override lower precedence patterns sources\. To use an exclamation ! as command line argument it is best placed between single quotes \'\'\. For example, \'!src\' +. +.IP "\(bu" 4 +If the pattern ends with a slash, it is removed for the purpose of the following description, but it would only find a match with a directory\. In other words, foo/ will match a directory foo and paths underneath it, but will not match a regular file or a symbolic link foo (this is consistent with the way how pathspec works in general in git)\. +. +.IP "\(bu" 4 +If the pattern does not contain a slash /, git treats it as a shell glob pattern and checks for a match against the pathname relative to the location of the \.gitignore file (relative to the toplevel of the work tree if not from a \.gitignore file)\. +. +.IP "\(bu" 4 +Otherwise, git treats the pattern as a shell glob suitable for consumption by fnmatch(3) with the FNM_PATHNAME flag: wildcards in the pattern will not match a / in the pathname\. For example, "Documentation/*\.html" matches "Documentation/git\.html" but not "Documentation/ppc/ppc\.html" or "tools/perf/Documentation/perf\.html"\. +. +.IP "\(bu" 4 +A leading slash matches the beginning of the pathname\. For example, "/*\.c" matches "cat\-file\.c" but not "mozilla\-sha1/sha1\.c"\. . .IP "" 0 . -.P -Running \fBgit\-ignore\fR without a pattern will display the current patterns: +.SH "EXAMPLES" +All arguments are optional so calling git\-ignore alone will display first the global then the local gitignore files: . .IP "" 4 . .nf $ git ignore -build -*\.o +Global gitignore: /home/alice/\.gitignore +# Numerous always\-ignore extensions +*\.diff +*\.err +*\.orig +*\.rej +*\.swo +*\.swp +*\.vi +*~ +*\.sass\-cache + +# OS or Editor folders +\.DS_Store +\.Trashes +\._* +Thumbs\.db +\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- +Local gitignore: \.gitignore +\.cache +\.project +\.settings +\.tmproj +nbproject +. +.fi +. +.IP "" 0 +. +.P +If you only want to see the global context use the \-\-global argument (for local use \-\-local): +. +.IP "" 4 +. +.nf + +$ git ignore +Global gitignore: /home/alice/\.gitignore +\.DS_Store +\.Trashes +\._* +Thumbs\.db +. +.fi +. +.IP "" 0 +. +.P +To quickly append a new pattern to the default/local context simply: +. +.IP "" 4 +. +.nf + +$ git ignore *\.log +Adding pattern(s) to: \.gitignore +\.\.\. adding \'*\.log\' +. +.fi +. +.IP "" 0 +. +.P +You can now configure any patterns without ever using an editor, with a context and pattern arguments: The resulting configuration is also returned for your convenience\. +. +.IP "" 4 +. +.nf + +$ git ignore \-\-local "" "# Temporary files" *\.tmp "*\.log" tmp/* "" "# Files I\'d like to keep" \'!work\' "" +Adding pattern(s) to: \.gitignore +\.\.\. adding \'\' +\.\.\. adding \'# Temporary files\' +\.\.\. adding \'index\.tmp\' +\.\.\. adding \'*\.log\' +\.\.\. adding \'tmp/*\' +\.\.\. adding \'\' +\.\.\. adding \'# Files I\'d like to keep\' +\.\.\. adding \'!work\' +\.\.\. adding \'\' + +Local gitignore: \.gitignore + +# Temporary files +index\.tmp *\.log + +# Files I\'d like to keep +!work . .fi . .IP "" 0 . .SH "AUTHOR" -Written by Tj Holowaychuk <\fItj@vision\-media\.ca\fR> +Written by Tj Holowaychuk <\fItj@vision\-media\.ca\fR> and Tema Bolshakov <\fItweekane@gmail\.com\fR> and Nick Lombard <\fIgithub@jigsoft\.co\.za\fR> . .SH "REPORTING BUGS" <\fIhttp://github\.com/visionmedia/git\-extras/issues\fR> diff --git a/man/git-ignore.html b/man/git-ignore.html index 4acd25f..8b36a77 100644 --- a/man/git-ignore.html +++ b/man/git-ignore.html @@ -61,11 +61,11 @@ AUTHOR REPORTING BUGS SEE ALSO - +
  1. git-ignore(1)
  2. -
  3. Git Extras
  4. +
  5. git-ignore(1)
@@ -76,35 +76,120 @@

SYNOPSIS

-

git-ignore [<pattern>...]

+

git-ignore [<context>] [<pattern> [<pattern>]...]

DESCRIPTION

-

Adds the given _pattern_s to a gitignore file.

+

Adds the given _pattern_s to a .gitignore file if it doesn't already exist.

OPTIONS

+

<context>

+ +

-l, --local

+ +

Sets the context to the .gitignore file in the current working directory. (default)

+ +

-g, --global

+ +

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

+ +

<pattern>

+ +

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

+ +

PATTERN FORMAT

+ +

Pattern format as described in the git manual

+ +
    +
  • A blank line matches no files, so it can serve as a separator for readability. To append a blank line use empty quotes "".

  • +
  • A line starting with # serves as a comment. For example, "# This is a comment"

  • +
  • An optional prefix ! which negates the pattern; any matching file excluded by a previous pattern will become included again. If a negated pattern matches, this will override lower precedence patterns sources. To use an exclamation ! as command line argument it is best placed between single quotes ''. For example, '!src'

  • +
  • If the pattern ends with a slash, it is removed for the purpose of the following description, but it would only find a match with a directory. In other words, foo/ will match a directory foo and paths underneath it, but will not match a regular file or a symbolic link foo (this is consistent with the way how pathspec works in general in git).

  • +
  • If the pattern does not contain a slash /, git treats it as a shell glob pattern and checks for a match against the pathname relative to the location of the .gitignore file (relative to the toplevel of the work tree if not from a .gitignore file).

  • +
  • Otherwise, git treats the pattern as a shell glob suitable for consumption by fnmatch(3) with the FNM_PATHNAME flag: wildcards in the pattern will not match a / in the pathname. For example, "Documentation/*.html" matches "Documentation/git.html" but not "Documentation/ppc/ppc.html" or "tools/perf/Documentation/perf.html".

  • +
  • A leading slash matches the beginning of the pathname. For example, "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c".

  • +
+ +

EXAMPLES

-

To lazy to open up .gitignore? me too! simply pass some patterns:

- -
$ git ignore build "*.o" "*.log"
-... added 'build'
-  ... added '*.o'
-... added '*.log'
-
- -

Running git-ignore without a pattern will display the current patterns:

+

All arguments are optional so calling git-ignore alone will display first the global then the local gitignore files:

$ git ignore
-build
-*.o
-*.log 
+Global gitignore: /home/alice/.gitignore
+# Numerous always-ignore extensions
+*.diff
+*.err
+*.orig
+*.rej
+*.swo
+*.swp
+*.vi
+*~
+*.sass-cache
+
+# OS or Editor folders
+.DS_Store
+.Trashes
+._*
+Thumbs.db
+---------------------------------
+Local gitignore: .gitignore
+.cache
+.project
+.settings
+.tmproj
+nbproject
+
+ +

If you only want to see the global context use the --global argument (for local use --local):

+ +
$ git ignore
+Global gitignore: /home/alice/.gitignore
+.DS_Store
+.Trashes
+._*
+Thumbs.db
+
+ +

To quickly append a new pattern to the default/local context simply:

+ +
$ git ignore *.log
+Adding pattern(s) to: .gitignore
+... adding '*.log'
+
+ +

You can now configure any patterns without ever using an editor, with a context and pattern arguments: +The resulting configuration is also returned for your convenience.

+ +
$ git ignore --local "" "# Temporary files" *.tmp "*.log" tmp/*  "" "# Files I'd like to keep" '!work'  ""
+Adding pattern(s) to: .gitignore
+... adding ''
+... adding '# Temporary files'
+... adding 'index.tmp'
+... adding '*.log'
+... adding 'tmp/*'
+... adding ''
+... adding '# Files I'd like to keep'
+... adding '!work'
+... adding ''
+
+Local gitignore: .gitignore
+
+# Temporary files
+index.tmp
+*.log
+
+# Files I'd like to keep
+!work
 

AUTHOR

-

Written by Tj Holowaychuk <tj@vision-media.ca>

+

Written by Tj Holowaychuk <tj@vision-media.ca> and Tema Bolshakov <tweekane@gmail.com> +and Nick Lombard <github@jigsoft.co.za>

REPORTING BUGS

@@ -117,7 +202,7 @@ build
  1. -
  2. March 2011
  3. +
  4. July 2012
  5. git-ignore(1)
diff --git a/man/git-ignore.md b/man/git-ignore.md index 2d7eead..e0fad92 100644 --- a/man/git-ignore.md +++ b/man/git-ignore.md @@ -1,35 +1,122 @@ git-ignore(1) -- Add .gitignore patterns -======================================= +======================================== ## SYNOPSIS -`git-ignore` [<pattern>...] +`git-ignore` [<context>] [<pattern> [<pattern>]...] ## DESCRIPTION -Adds the given _pattern_s to a gitignore file. +Adds the given _pattern_s to a .gitignore file if it doesn't already exist. ## OPTIONS + <context> + + -l, --local + + Sets the context to the .gitignore file in the current working directory. (default) + + -g, --global + + Sets the context to the global gitignore file fol the current user. + + <pattern> + + A space delimited list of patterns to append to the file in context. + +### PATTERN FORMAT + +Pattern format as described in the git manual + + * A blank line matches no files, so it can serve as a separator for readability. To append a blank line use empty quotes "". + + * A line starting with # serves as a comment. For example, "# This is a comment" + + * An optional prefix ! which negates the pattern; any matching file excluded by a previous pattern will become included again. If a negated pattern matches, this will override lower precedence patterns sources. To use an exclamation ! as command line argument it is best placed between single quotes ''. For example, '!src' + + * If the pattern ends with a slash, it is removed for the purpose of the following description, but it would only find a match with a directory. In other words, foo/ will match a directory foo and paths underneath it, but will not match a regular file or a symbolic link foo (this is consistent with the way how pathspec works in general in git). + + * If the pattern does not contain a slash /, git treats it as a shell glob pattern and checks for a match against the pathname relative to the location of the .gitignore file (relative to the toplevel of the work tree if not from a .gitignore file). + + * Otherwise, git treats the pattern as a shell glob suitable for consumption by fnmatch(3) with the FNM_PATHNAME flag: wildcards in the pattern will not match a / in the pathname. For example, "Documentation/*.html" matches "Documentation/git.html" but not "Documentation/ppc/ppc.html" or "tools/perf/Documentation/perf.html". + + * A leading slash matches the beginning of the pathname. For example, "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c". + + ## EXAMPLES - To lazy to open up _.gitignore_? me too! simply pass some patterns: - - $ git ignore build "*.o" "*.log" - ... added 'build' - ... added '*.o' - ... added '*.log' - - Running `git-ignore` without a pattern will display the current patterns: + All arguments are optional so calling git-ignore alone will display first the global then the local gitignore files: $ git ignore - build - *.o - *.log + Global gitignore: /home/alice/.gitignore + # Numerous always-ignore extensions + *.diff + *.err + *.orig + *.rej + *.swo + *.swp + *.vi + *~ + *.sass-cache + + # OS or Editor folders + .DS_Store + .Trashes + ._* + Thumbs.db + --------------------------------- + Local gitignore: .gitignore + .cache + .project + .settings + .tmproj + nbproject + +If you only want to see the global context use the --global argument (for local use --local): + + $ git ignore + Global gitignore: /home/alice/.gitignore + .DS_Store + .Trashes + ._* + Thumbs.db + +To quickly append a new pattern to the default/local context simply: + + $ git ignore *.log + Adding pattern(s) to: .gitignore + ... adding '*.log' + +You can now configure any patterns without ever using an editor, with a context and pattern arguments: +The resulting configuration is also returned for your convenience. + + $ git ignore --local "" "# Temporary files" *.tmp "*.log" tmp/* "" "# Files I'd like to keep" '!work' "" + Adding pattern(s) to: .gitignore + ... adding '' + ... adding '# Temporary files' + ... adding 'index.tmp' + ... adding '*.log' + ... adding 'tmp/*' + ... adding '' + ... adding '# Files I'd like to keep' + ... adding '!work' + ... adding '' + + Local gitignore: .gitignore + + # Temporary files + index.tmp + *.log + + # Files I'd like to keep + !work ## AUTHOR -Written by Tj Holowaychuk <> +Written by Tj Holowaychuk <> and Tema Bolshakov <> +and Nick Lombard <> ## REPORTING BUGS