]> 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:

add a vim modeline to preserve joey's tabbing prefs
[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 # one $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 #lib = git_fake_bare_worktree $HOME
14 #checkout = git_fake_bare_checkout git://... .dotfiles
15
16 lib =
17         # called to tell git where the worktree is
18         git_fake_bare_worktree() {
19                 GIT_WORK_TREE="$1"; export GIT_WORK_TREE
20         }
21         # git doesn't have an easy way to check out such a repo, so
22         # do it by hand
23         git_fake_bare_checkout() {
24                 url="$1"
25                 repo="$2"
26                 GIT_WORK_TREE= git clone --no-checkout "$url" "$repo"
27                 cd "$repo"
28                 mkdir -p "$GIT_WORK_TREE"
29                 git read-tree HEAD
30                 git config core.worktree "$GIT_WORK_TREE"
31                 git checkout-index -a --prefix="$worktree" || true
32                 mv .git/* .
33                 rmdir .git
34         }
35
36 git_fake_bare_test = 
37         test -d "$MR_REPO"/refs/heads && test -d "$MR_REPO"/refs/tags &&
38         test -d "$MR_REPO"/objects && test -f "$MR_REPO"/config &&
39         test "$(GIT_CONFIG="$MR_REPO"/config git-config --get core.bare)" = false
40
41 git_fake_bare_update =
42         # all this is because of a bug in git-fetch, which requires GIT_DIR set
43         local git_dir_override; git_dir_override=.git
44         case "$(get_git_repo_type "$MR_REPO")" in
45                 fake-bare) git_dir_override="$MR_REPO";;
46         esac
47         args="$@"
48         [ -z "$args" ] && args="-t origin master"
49         eval GIT_DIR="$git_dir_override" git pull "$args"
50
51 git_fake_bare_status = git status "$@" || true
52
53 git_fake_bare_commit = error "commit does not work for fake bare git repositories (yet)."
54
55 git_fake_bare_diff = error "diff does not work for fake bare git repositories (yet)."
56
57 git_fake_bare_log = git log "$@"
58
59 git_fake_bare_register = 
60         url="$(LANG=C GIT_CONFIG=config git-config --get remote.origin.url)" || true
61         if [ -z "$url" ]; then
62                 error "cannot determine git url"
63         fi
64         worktree="$(git-config --get core.worktree)" || true
65         if [ -z "$worktree" ]; then
66                 error "git worktree is not set"
67         fi
68         worktree="${worktree%%/}/"
69         if [ ! -d "$worktree" ]; then
70                 error "git worktree $worktree does not exist"
71         fi
72         mr -c "$MR_CONFIG" config "`pwd`" lib="git_fake_bare_worktree '$worktree'"
73         echo "Registering git url: $url in $MR_CONFIG (with worktree $worktree)"
74         mr -c "$MR_CONFIG" config "`pwd`" checkout="git_fake_bare_checkout '$url' '$MR_REPO'"
75
76 # vim:sw=8:sts=0:ts=8:noet