From df84a87c06217dc9949573aed6c1777cb969f1db Mon Sep 17 00:00:00 2001 From: Ivan Zakharyaschev Date: Thu, 16 Jan 2014 13:19:02 +0400 Subject: [PATCH] restore: Implemented with a rebase (to more cleanly keep local unworthy changes separated from the saved config). TODO: implement this similarly to stash! --- gitgitconfig-restore | 41 ++++++++++++++-------- gitgitconfig-save | 5 +++ ...oteadd-save-push-u-save-push-u-clone-restore.sh | 33 +++++++++++++++++ 3 files changed, 65 insertions(+), 14 deletions(-) create mode 100755 tests/remoteadd-save-push-u-save-push-u-clone-restore.sh diff --git a/gitgitconfig-restore b/gitgitconfig-restore index 4df6987..3ef0a00 100755 --- a/gitgitconfig-restore +++ b/gitgitconfig-restore @@ -2,10 +2,30 @@ # We don't want (for now) to work with .git in nonstandard locations. #readonly REPOCONFIGDIR="$(git rev-parse --git-dir)" + readonly REPODIR="$(git rev-parse --show-toplevel)" +# Idea: +# GITCONFIG/master branch in our main working repo (origin) +# should hold the config prepared for saving and restoring +# (i.e., no junk commits). +if [[ ! -e .git/refs/heads/GITCONFIG/master ]]; then + if ! [[ "$1" ]]; then + { + echo $"Don't know where to pull from:" + echo $"your main repo has no GITCONFIG/master" + echo $"and you haven't given a remote name as an arg!" + exit 1 + }>&2 + fi + git fetch -v "$1" GITCONFIG/master + # We expect this to be done manually otherwise. + git branch GITCONFIG/master "$1"/GITCONFIG/master +fi + cd "$REPODIR"/.git +# Initialization: if [[ -d .git ]]; then # Already initialized. # Please, add and commit interesting files beforehand manually, @@ -16,22 +36,15 @@ else pushd .. gitgitconfig-init popd + git add . git commit -m 'Initial .git/config etc. (needed for automatic operation).' fi - -# We'd like to pull from some /GITCONFIG/master in origin -# (which is expected to be your main working repo) -# to restore your saved .git/config. -if [[ "$1" ]]; then - git pull -v --no-edit origin "$1"/GITCONFIG/master -else - # Pulling from GITCONFIG/master in origin. - # (We have set up such behavior in our gitgitconfig-init.) - git pull -v --no-edit - # Unfortunately, this is rarely useful, because your main - # working repo won't be a mirror of a remote, and hence won't - # have GITCONFIG/master after a clone. -fi + +# Pulling from GITCONFIG/master in origin: +# (We have set up such behavior in our gitgitconfig-init.) +git pull --rebase -v --no-edit + +# Our local modifications remain ontop of the previously saved config. # We'll see how merging works out. \ No newline at end of file diff --git a/gitgitconfig-save b/gitgitconfig-save index 621ea09..0c62e0e 100755 --- a/gitgitconfig-save +++ b/gitgitconfig-save @@ -2,6 +2,7 @@ # We don't want (for now) to work with .git in nonstandard locations. #readonly REPOCONFIGDIR="$(git rev-parse --git-dir)" + readonly REPODIR="$(git rev-parse --show-toplevel)" cd "$REPODIR"/.git @@ -19,6 +20,10 @@ else git commit -m 'Saving your .git/config etc. automatically.' fi +# I wanted to squash all local changes into one commit (to avoid +# the extra junk from the inital config), but that's not a trivial command. +#git rebase + # We'd like to push our local to GITCONFIG/ # in your main working repo. git push origin refs/heads/*:refs/heads/GITCONFIG/* diff --git a/tests/remoteadd-save-push-u-save-push-u-clone-restore.sh b/tests/remoteadd-save-push-u-save-push-u-clone-restore.sh new file mode 100755 index 0000000..02798c8 --- /dev/null +++ b/tests/remoteadd-save-push-u-save-push-u-clone-restore.sh @@ -0,0 +1,33 @@ +#!/bin/bash -ex + +git init --bare server.git + +mkdir A +cd A + +git init +echo a > a +git add a +git commit -m 'A.' +git remote add server "$(cd ..; pwd)"/server.git +git push -u --mirror server +gitgitconfig-save +git push -u --mirror server +pushd .git +git commit -a -m 'Saving an updated config for the test.' +popd +gitgitconfig-save +git push -u --mirror server + +cd .. + +git clone -o server server.git B +cd B + +gitgitconfig-restore server + +if [[ "$(git remote)" == "$(echo server)" ]]; then + exit 0 +else + exit 1 +fi -- 2.11.4.GIT