3 # git-darcs - bidirectional operation between a darcs repo and git
5 # Copyright (c) 2008 by Miklos Vajna <vmiklos@frugalware.org>
7 # Based on git-bzr, which is
9 # Copyright (c) 2008 Pieter de Bie <pdebie@ai.rug.nl>
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
33 if ! [ -n "$name" -a -n "$location" ]; then
34 echo "Usage: git darcs add name location [darcs-fast-export options]"
37 if git remote show |
grep -q $name; then
38 echo "There is already a remote with that name"
41 if [ -n "$(git config git-darcs.$name.location)" ]; then
42 echo "There is already a darcs repo with that name"
45 if [ ! -d $location/_darcs
]; then
46 echo "Remote is not a darcs repository"
49 git config git-darcs.
$name.location
$location
50 git config git-darcs.
$name.darcs-fast-export-options
"$*"
51 echo "Darcs repo $name added. You can fetch it with 'git darcs fetch $name'"
52 if ! [ -z "$*" ]; then
53 echo "darcs-fast-export will get options: $*"
59 l
=$
(git config git-darcs.
$remote.location
)
61 echo "Cannot find darcs remote with name '$remote'." >&2
71 if ! [ -n "$remote" -a -z "$*" ]; then
72 echo "Usage: git darcs fetch reponame"
75 location
=$
(get_location
$remote)
76 git_map
=$git_dir/darcs-git
/$remote-git-map
77 darcs_map
=$git_dir/darcs-git
/$remote-darcs-map
78 common_opts
="--working $git_dir/darcs-git/repo --logfile $git_dir/darcs-git/fetch.log --git-branch=darcs/$remote"
79 dfe_opts
=$
(git config git-darcs.
$remote.darcs-fast-export-options
)
80 if [ ! -f $git_map -a ! -f $darcs_map ]; then
81 echo "There doesn't seem to be an existing refmap."
82 echo "Doing an initial import"
83 mkdir
-p $git_dir/darcs-git
84 darcs-fast-export
--export-marks=$darcs_map $common_opts $dfe_opts $location | \
85 git fast-import
--export-marks=$git_map
86 elif [ -f $git_map -a -f $darcs_map ]; then
87 echo "Updating remote $remote"
88 old_rev
=$
(git rev-parse darcs
/$remote)
89 darcs-fast-export
--import-marks=$darcs_map --export-marks=$darcs_map $common_opts $dfe_opts $location | \
90 git fast-import
--quiet --import-marks=$git_map --export-marks=$git_map
91 new_rev
=$
(git rev-parse darcs
/$remote)
92 if [ "$old_rev" != "$new_rev" ]; then
93 echo "Fetched the following updates:"
94 git shortlog
$old_rev..
$new_rev
96 echo "Nothing fetched."
100 echo "One of the mapfiles is missing! Something went wrong!"
109 if ! [ -n "$remote" -a -z "$*" ]; then
110 echo "Usage: git darcs pull reponame"
114 # see if we need to merge or rebase
115 branch
=$
(git symbolic-ref HEAD|
sed 's|.*/||')
116 if [ "$(git config branch.$branch.rebase)" = "true" ]; then
117 git rebase darcs
/$remote
119 git merge darcs
/$remote
127 if ! [ -n "$remote" -a -z "$*" ]; then
128 echo "Usage: git darcs push reponame"
131 location
=$
(get_location
$remote)
132 if [ -n "$(git rev-list --left-right HEAD...darcs/$remote | sed -n '/^>/ p')" ]; then
133 echo "HEAD is not a strict child of $remote, cannot push. Merge first"
136 if [ -z "$(git rev-list --left-right HEAD...darcs/$remote | sed -n '/^</ p')" ]; then
137 echo "Nothing to push. Commit something first"
140 git_map
=$git_dir/darcs-git
/$remote-git-map
141 darcs_map
=$git_dir/darcs-git
/$remote-darcs-map
142 if [ ! -f $git_map -o ! -f $darcs_map ]; then
143 echo "We do not have refmapping yet. Then how can I push?"
146 echo "Pushing the following updates:"
147 git shortlog darcs
/$remote..
148 git fast-export
--import-marks=$git_map --export-marks=$git_map HEAD | \
149 (cd $location; darcs-fast-import
--import-marks=$darcs_map --export-marks=$darcs_map \
150 --logfile $git_dir/darcs-git
/push.log
)
152 git update-ref darcs
/$remote HEAD
156 # List the darcs remotes
161 git config
-l |
sed -n -e '/git-darcs\..*/ {s/git-darcs\.//; s/\.location=.*//p}'
167 git config
-l |
sed -n -e '/git-darcs\..*/ {s/git-darcs\.//; s/\.location=/\t/p}'
172 echo "Usage: git darcs list [-v|--verbose]"
176 # Find the darcs commit(s) supporting a git SHA1 prefix
181 if [ -z "$sha1" -o -n "$*" ]
183 echo "Usage: git darcs find-darcs <sha1-prefix>"
186 for remote
in $git_dir/darcs
/*
188 remote
=`basename $remote`
189 git_map
=$git_dir/darcs-git
/$remote-git-map
190 darcs_map
=$git_dir/darcs-git
/$remote-darcs-map
191 if [ ! -f $git_map -o ! -f $darcs_map ]
193 echo "Missing mappings for remote $remote"
196 for row
in `sed -n -e "/:.* $sha1.*/ s/[^ ]*/&/p" $git_map`
198 sed -n -e "/$row / {s/[^ ]*//; s/.*/$remote\t&/p}" $darcs_map
203 # Find the git commit(s) supporting a darcs patch prefix
208 if [ -z "$patch" -o -n "$*" ]
210 echo "Usage: git darcs find-git <patch-prefix>"
213 for remote
in $git_dir/darcs
/*
215 remote
=`basename $remote`
216 git_map
=$git_dir/darcs-git
/$remote-git-map
217 darcs_map
=$git_dir/darcs-git
/$remote-darcs-map
218 if [ ! -f $git_map -o ! -f $darcs_map ]
220 echo "Missing mappings for remote $remote"
223 for row
in `sed -n -e "/:.* $patch.*/ s/[^ ]*/&/p" $darcs_map`
225 sed -n -e "/$row / {s/[^ ]* \(.*\)/$remote\t\1/p}" $git_map
230 git rev-parse
2> /dev
/null
232 echo "Must be inside a git repository to work"
236 git_dir
=$
(git rev-parse
--git-dir)
245 add|push|fetch|pull|list
)
254 echo "Usage: git darcs [COMMAND] [OPTIONS]"
255 echo "Commands: add, push, fetch, pull, list, find-darcs, find-git"
261 up
=$
(git rev-parse
--show-cdup)
262 [ -z "$up" ] && up
="."