Created
December 1, 2012 22:17
-
-
Save bitc/4185595 to your computer and use it in GitHub Desktop.
Use darcs to version control private files in a git repository
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# init_darcs_in_git.sh | |
# | |
# This is a script that initializes a darcs repository that can be used for | |
# managing private files in a git repository that should not be tracked by git | |
# | |
# The system is a simple hack, but it works quite elegantly in practice, darcs | |
# and git do not get in each others way. | |
# | |
# The private files that are managed by darcs are automatically written to | |
# .git/info/exclude using a darcs record posthook so that | |
set -e | |
if [ ! -d .git ]; then | |
echo "Error: You must be inside a git repository" | |
exit 1 | |
fi | |
if [ -d _darcs ]; then | |
echo "Error: There is already a darcs repository here (_darcs exists)" | |
exit 2 | |
fi | |
if grep -q -v "^#" .git/info/exclude 2> /dev/null; then | |
echo "Error: .git/info/exclude is not empty. Back it up, remove the patterns, and try again." | |
echo "For your information, it contains the following patterns:" | |
echo | |
grep -v "^#" .git/info/exclude | |
exit 3 | |
fi | |
echo "-> Running darcs init" | |
darcs init | |
echo "-> Configuring _darcs/prefs/defaults" | |
cat > _darcs/prefs/defaults <<EOF | |
record posthook (echo '# THIS FILE IS AUTOMATICALLY GENERATED DO NOT EDIT'; echo '/_darcs/'; darcs show files --no-directories --no-pending | sed 's/^.\//\//'; darcs show contents .gitexclude 2>/dev/null; true) > .git/info/exclude | |
EOF | |
echo "-> Configuring initial .git/info/exclude" | |
cat > .git/info/exclude <<EOF | |
# THIS FILE IS AUTOMATICALLY GENERATED DO NOT EDIT | |
/_darcs/ | |
EOF | |
echo "-> All Done!" | |
cat <<EOF | |
Instructions: | |
1. Use "git status" to see the list of Untracked files | |
(Don't use "darcs whatsnew -l": it's useless). | |
2. Use "darcs add foo.txt" to add foo.txt to the private darcs repository | |
3. Run "darcs whatsnew -s" at any time to see which private files have | |
modifications (similar to "git status") | |
4. Run "darcs whatsnew" at any time to see the actual modifications. You | |
can also supply an additional file argument (similar to "git diff"). | |
5. Run "darcs record" and follow the interactive prompts | |
(similar to "git add" followed by "git commit") | |
6. To completely ignore/exclude files (such as temporary files): | |
A. Create a .gitexlude file in the root directory | |
B. Fill it with exclude patterns (using the git format) | |
C. darcs add .gitexclude | |
D. darcs record | |
7. To see a list of the private files that are tracked by darcs use | |
"darcs show files --no-directories --no-pending" | |
EOF | |
# TODO Here is a command that can be used to see if there are any files that | |
# tracked both by git and darcs (bad!) | |
# | |
# Maybe this can be integrated somehow to warn the user about the conflict | |
(git ls-tree --full-tree -r HEAD --name-only; darcs show files --no-directories --no-pending | sed 's/^.\///') | sort | uniq -d |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment