From: Oleg Broytman Date: Wed, 15 Jan 2014 05:44:42 +0000 (+0400) Subject: Initial commit X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=38ab9e31c986f27acc4f45364bacfac18edf7bc4;p=git-scripts.git Initial commit --- 38ab9e31c986f27acc4f45364bacfac18edf7bc4 diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..5da4ec9 --- /dev/null +++ b/README.txt @@ -0,0 +1,14 @@ +git scripts +=========== + +Small scripts I use. Public domain. + +svn/ - scripts for converting a Subversion repository to git using git-svn. +See svn/README.txt. + +clone2current - clone a repository to ~/current/projects; add remote "current" +to the original repository to pull updates from. + +publish2web - clone a repository to ~/Internet/WWW/htdocs/git.phdru.name from +where it will be copied to git.phdru.name web site.; add remote "web" +to the original repository to push updates. diff --git a/clone2current b/clone2current new file mode 100755 index 0000000..583a895 --- /dev/null +++ b/clone2current @@ -0,0 +1,29 @@ +#! /bin/sh + +if [ -z "$1" ]; then + echo "Usage: $0 repoistory" >&2 + exit 1 +fi + +cd "$1" && source_dir="`pwd`" && + +if [ ! -d ".git" ]; then + echo "$source_dir is not a repoistory (.git isn't found)" >&2 + exit 1 +fi && + +cd "$HOME"/current/projects && +dest_dir="`basename \"$source_dir\"`" && +git clone "$source_dir" "$dest_dir" && + +cd "$dest_dir" && +if [ "`cat \"$source_dir\"/.git/description`" = \ + "Unnamed repository; edit this file 'description' to name the repository." ] +then + "${VISUAL:-${EDITOR:-vi}}" "$source_dir"/.git/description .git/description +else + cp -p "$source_dir"/.git/description .git +fi && + +cd "$source_dir" && +exec git remote add current "$HOME"/current/projects/"$dest_dir" diff --git a/publish2web b/publish2web new file mode 100755 index 0000000..2708364 --- /dev/null +++ b/publish2web @@ -0,0 +1,40 @@ +#! /bin/sh + +if [ -z "$1" ]; then + echo "Usage: $0 repoistory" >&2 + exit 1 +fi + +umask 022 && +cd "$1" && source_dir="`pwd`" && + +if [ ! -d ".git" ]; then + echo "$source_dir is not a repoistory (.git isn't found)" >&2 + exit 1 +fi && + +cd "$HOME"/tmp && +dest_dir="`basename \"$source_dir\"`".git && +git clone --mirror --config core.sharedRepository=0644 "$source_dir" "$dest_dir" && + +cd "$dest_dir" && +git gc --aggressive && git fsck --strict && +cp -p hooks/post-update.sample hooks/post-update && hooks/post-update && +cp -p "$HOME"/Internet/WWW/htdocs/git.phdru.name/phdru.name.git/git-daemon-export-ok . && +if [ "`cat \"$source_dir\"/.git/description`" = \ + "Unnamed repository; edit this file 'description' to name the repository." ] +then + "${VISUAL:-${EDITOR:-vi}}" "$source_dir"/.git/description description +else + cp -p "$source_dir"/.git/description . && chmod a+r description +fi && +if [ -f "$source_dir"/README.html ]; then + cp -p "$source_dir"/README.html . && chmod a+r README.html +fi && + +cd .. && +mv "$dest_dir" "$HOME"/Internet/WWW/htdocs/git.phdru.name && + +umask 027 && +cd "$source_dir" && +exec git remote add --mirror=push web "$HOME"/Internet/WWW/htdocs/git.phdru.name/"$dest_dir" diff --git a/svn/README.txt b/svn/README.txt new file mode 100644 index 0000000..2f09308 --- /dev/null +++ b/svn/README.txt @@ -0,0 +1,38 @@ +Convert a Subversion repository to git +====================================== + +These scripts are for converting a Subversion repository to git using +git-svn. The scripts are based on the code from the book "ProGit" +by Scott Chacon. I'm not sure about their legal status; I'd put them +into public domain. + +Let's imagine you want to convert http://svn.example.org/ to git. + +First, edit authors.txt. Replace my name and email with yours as the +``(no author)``. You don't want me to be the committer of your null +commit, do you? + +Run + + get-authors http://svn.example.org/ + +Edit authors.txt again - set names and emails for committers. + +Run + + clone http://svn.example.org/ [$output_directory] + +Script ``clone`` tries to deduce the output directory from the given +SVN URL by using base name of the path, but in our case there is no path +so you must provide the output directory: + + clone http://svn.example.org/ example + +In case of an URL like http://example.org/svn/project/ ``clone`` doesn't +need the output directory. + +Run + + clone http://svn.example.org/svn/project/ + +and ``clone`` will happily convert the URL to ``project`` directory. diff --git a/svn/authors.txt b/svn/authors.txt new file mode 100644 index 0000000..9db11a4 --- /dev/null +++ b/svn/authors.txt @@ -0,0 +1,2 @@ +phd = Oleg Broytman +(no author) = Oleg Broytman diff --git a/svn/clone b/svn/clone new file mode 100755 index 0000000..850c1f2 --- /dev/null +++ b/svn/clone @@ -0,0 +1,47 @@ +#! /bin/sh + +if [ -z "$1" ]; then + echo "Usage: $0 svn_url [dir]" >&2 + exit 1 +fi + +url="$1" + +if [ ! -f authors.txt ]; then + echo "Run \"get-authors $1\" first" >&2 + exit 2 +fi + +if [ -z "$2" ]; then + dir="`basename $url`" +else + dir="$2" +fi + +if [ -z "$dir" ]; then + echo "Usage: $0 svn_url [dir]" >&2 + exit 1 +fi + +# init + fetch +git svn clone "$url" --authors-file=authors.txt --stdlayout "$dir" && +cd "$dir" && + +# fix references +cp -rf .git/refs/remotes/tags/* .git/refs/tags/ && +rm -rf .git/refs/remotes/tags +cp -rf .git/refs/remotes/* .git/refs/heads/ && +rm -rf .git/refs/remotes + +# convert svn:ignore to .gitignore +git svn create-ignore && +git commit -m "Add .gitignore" && + +# preserve authors.txt +cp -p ../authors.txt .git/info && +git config --local --path svn.authorsfile .git/info/authors.txt + +git svn gc && +git gc --aggressive && +echo "Cloned from $url using git-svn" >.git/description && +exec "${VISUAL:-${EDITOR:-vi}}" .git/description diff --git a/svn/get-authors b/svn/get-authors new file mode 100755 index 0000000..975ef95 --- /dev/null +++ b/svn/get-authors @@ -0,0 +1,11 @@ +#! /bin/sh + +if [ -z "$1" ]; then + echo "Usage: $0 svn_url" >&2 + exit 1 +fi + +url="$1" + +svn log --xml "$url" | grep -F author | sort -u | + sed 's/^<[^>]\+>\(.\+\)<.\+>$/\1 = /' >>authors.txt