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

make sure we move repo into place first before using it
[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                 set -x
20                 local url; url="$1"
21                 local repo; repo="$2"
22                 local worktree; worktree="$3"
23                 git clone --no-checkout "$url" "$repo"
24                 cd "$repo"
25                 mkdir -p "$worktree"
26                 PWD="`pwd`"
27                 mv .git/* .
28                 rmdir .git
29                 GIT_DIR="$PWD" git read-tree HEAD
30                 GIT_DIR="$PWD" git checkout-index -a --prefix="$worktree" || true
31                 GIT_DIR="$PWD" git config core.worktree "$worktree"
32                 set +x
33         }
34         git_get_worktree() {
35                 local worktree
36                 worktree="$(git config --get core.worktree)" || true
37                 if [ -z "$worktree" ]; then
38                         error "git worktree is not set"
39                 fi
40                 worktree="${worktree%%/}/"
41                 if [ ! -d "$worktree" ]; then
42                         error "git worktree $worktree does not exist"
43                 fi
44                 echo "$worktree"
45         }
46
47 git_fake_bare_test = 
48         test -d "$MR_REPO"/refs/heads && test -d "$MR_REPO"/refs/tags &&
49         test -d "$MR_REPO"/objects && test -f "$MR_REPO"/config &&
50         test "$(GIT_DIR="$MR_REPO" git config --get core.bare)" = false
51
52 git_fake_bare_update =
53         args="$@"
54         [ -z "$args" ] && args="-t origin master"
55         GIT_DIR="$MR_REPO" git pull $args
56
57 git_fake_bare_status = GIT_DIR="$MR_REPO" git status "$@" || true
58
59 git_fake_bare_commit =
60         cd "$(git_get_worktree)"
61         GIT_DIR="$MR_REPO" git commit -a "$@"
62         GIT_DIR="$MR_REPO" git push --all
63
64 git_fake_bare_record = 
65         cd "$(git_get_worktree)"
66         GIT_DIR="$MR_REPO" git commit -a "$@"
67
68 git_fake_bare_diff =
69         cd "$(git_get_worktree)"
70         GIT_DIR="$MR_REPO" git diff "$@"
71
72 git_fake_bare_log = GIT_DIR="$MR_REPO" git log "$@"
73
74 git_fake_bare_register = 
75         url="$(LC_ALL=C GIT_CONFIG=config git config --get remote.origin.url)" || true
76         if [ -z "$url" ]; then
77                 error "cannot determine git url"
78         fi
79         worktree="$(git_get_worktree)"
80         echo "Registering git url: $url in $MR_CONFIG (with worktree $worktree)"
81         mr -c "$MR_CONFIG" config "`pwd`" \
82                 checkout="git_fake_bare_checkout '$url' '$MR_REPO' '$worktree'"
83
84 # vim:sw=8:sts=0:ts=8:noet