Skip to content

Instantly share code, notes, and snippets.

@xkr47
Last active December 8, 2023 09:58
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save xkr47/8bc17d69f5b8733250c0 to your computer and use it in GitHub Desktop.
Save xkr47/8bc17d69f5b8733250c0 to your computer and use it in GitHub Desktop.
cvsignore -> gitignore converter
#!/bin/sh
if [ ! -d .git ]; then
echo ERROR: Please run this in the root of the git repository
exit 1
fi
cat > .gitignore <<'EOF'
# CVS global ignores
RCS
SCCS
CVS
CVS.adm
RCSLOG
cvslog.*
tags
TAGS
.make.state
.nse_depinfo
*~
#*
.#*
,*
_$*
*$
*.old
*.bak
*.BAK
*.orig
*.rej
.del-*
*.a
*.olb
*.o
*.obj
*.so
*.exe
*.Z
*.elc
*.ln
core
EOF
split_cvsignore_line () {
perl -pe 's!^\s+!!;s!\s+!\n!g;'
}
if [ -r $HOME/.cvsignore -o "$CVSIGNORE" ]; then
echo '# User global ignores'
[ -r $HOME/.cvsignore ] && cat $HOME/.cvsignore | split_cvsignore_line
[ "$CVSIGNORE" ] && echo "$CVSIGNORE" | split_cvsignore_line
echo
fi >> .gitignore
echo '# Project ignores (converted from .cvsignore files)' >> .gitignore
find -name .cvsignore | while read f ; do
dir="$(dirname "$f" | sed -r 's:^\.::')"
cat "$f" | split_cvsignore_line | awk '{print "'"$dir"'/"$1}' >> .gitignore
git rm -f "$f"
done
git add .gitignore
git commit -m 'Automatically converted .cvsignore files to .gitignore using https://gist.github.com/xkr47/8bc17d69f5b8733250c0'
@xkr47
Copy link
Author

xkr47 commented Jun 12, 2015

Improved version of http://stackoverflow.com/a/24016535/1356047

  • adds the default ignores implied by CVS
  • adds user ignores from ~/.cvsignore and $CVSIGNORE environment variable (if present)
  • changes all filename processing to ensure special characters (like spaces) in .cvsignore paths get correctly processed
  • split multiple entries on single .cvsignore line to multiple .gitignore lines
  • automatically creates a commit that
    • removes the .cvsignore files
    • adds the .gitignore file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment