]> git.madduck.net Git - code/myrepos.git/blob - lib/git-fake-bare

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

4c2a72cba6efeb5e263339898e3dc5f385c5e185
[code/myrepos.git] / lib / git-fake-bare
1 # An example of how to add a new revision control system type to mr.
2 # git fake bare repositories have a detached workspace. One potential
3 # application is storing dotfiles in git, keeping them checked out in
4 # ones $HOME, but checked into different git repositories. This file adds
5 # support for them, separate from the normal git support.
6
7 # To make mr use this file, add a line like this inside the [DEFAULT]
8 # section of your ~/.mrconfig
9 #include = cat /usr/share/mr/git-fake-bare
10
11 # And an example repo using it would look something like:
12 #[.dotfiles]
13 #checkout = git_fake_bare_checkout git://... .dotfiles <worktree, eg. ..>
14
15 lib =
16         # git doesn't have an easy way to check out such a repo, so
17         # do it by hand
18         git_fake_bare_checkout() {
19                 url="$1"
20                 repo="$2"
21                 worktree="$3"
22                 git clone --no-checkout "$url" "$repo"
23                 cd "$repo"
24                 mkdir -p "$worktree"
25                 git read-tree HEAD
26                 git checkout-index -a --prefix="$worktree" || true
27                 git config core.worktree "$worktree"
28                 mv .git/* .
29                 rmdir .git
30         }
31         git_get_worktree() {
32                 local worktree
33                 worktree="$(git config --get core.worktree)" || true
34                 if [ -z "$worktree" ]; then
35                         error "git worktree is not set"
36                 fi
37                 worktree="${worktree%%/}/"
38                 if [ ! -d "$worktree" ]; then
39                         error "git worktree $worktree does not exist"
40                 fi
41                 echo "$worktree"
42         }
43
44 git_fake_bare_test = 
45         test -d "$MR_REPO"/refs/heads && test -d "$MR_REPO"/refs/tags &&
46         test -d "$MR_REPO"/objects && test -f "$MR_REPO"/config &&
47         test "$(GIT_CONFIG="$MR_REPO"/config git config --get core.bare)" = false
48
49 git_fake_bare_update =
50         args="$@"
51         [ -z "$args" ] && args="-t origin master"
52         eval GIT_DIR="$MR_REPO" git pull "$args"
53
54 git_fake_bare_status = git status "$@" || true
55
56 git_fake_bare_commit = error "commit does not work for fake bare git repositories (yet)."
57
58 git_fake_bare_record = error "record does not work for fake bare git repositories (yet)."
59
60 git_fake_bare_diff =
61         cd "$(git_get_worktree)"
62         eval GIT_DIR="$MR_REPO" git diff "$@"
63
64 git_fake_bare_log = git log "$@"
65
66 git_fake_bare_register = 
67         url="$(LC_ALL=C GIT_CONFIG=config git config --get remote.origin.url)" || true
68         if [ -z "$url" ]; then
69                 error "cannot determine git url"
70         fi
71         worktree="$(git_get_worktree)"
72         echo "Registering git url: $url in $MR_CONFIG (with worktree $worktree)"
73         mr -c "$MR_CONFIG" config "`pwd`" \
74                 checkout="git_fake_bare_checkout '$url' '$MR_REPO' '$worktree'"
75
76 # vim:sw=8:sts=0:ts=8:noet