restore: Implemented with rebase and reset. (Do not forget to reset manually in case...
[gitgitconfig.git] / gitgitconfig-restore
blob1956ce6a071c855382f4e25aa9ef6525772bbafe
1 #!/bin/bash -ex
3 # We don't want (for now) to work with .git in nonstandard locations.
4 #readonly REPOCONFIGDIR="$(git rev-parse --git-dir)"
6 readonly REPODIR="$(git rev-parse --show-toplevel)"
8 # Idea:
9 # GITCONFIG/master branch in our main working repo (origin)
10 # should hold the config prepared for saving and restoring
11 # (i.e., no junk commits).
12 if [[ ! -e .git/refs/heads/GITCONFIG/master ]]; then
13 if ! [[ "$1" ]]; then
15 echo $"Don't know where to pull from:"
16 echo $"your main repo has no GITCONFIG/master"
17 echo $"and you haven't given a remote name as an arg!"
18 exit 1
19 }>&2
21 git fetch -v "$1" GITCONFIG/master
22 # We expect this to be done manually otherwise.
23 git branch GITCONFIG/master "$1"/GITCONFIG/master
26 cd "$REPODIR"/.git
28 # Initialization:
29 if [[ -d .git ]]; then
30 # Already initialized.
31 # Please, add and commit interesting files beforehand manually,
32 # otherwise merge will fail.
34 else
35 # Not initialized.
36 pushd ..
37 gitgitconfig-init
38 popd
41 # Like git stash --include-untracked:
42 git add -A .
43 git commit --allow-empty -m 'Automatically saving your local modifications to the config (for "stashing").'
44 echo $"Afterwards, do not forget to: " 'git reset --mixed HEAD^'
46 # Pulling from GITCONFIG/master in origin:
47 # (We have set up such behavior in our gitgitconfig-init.)
48 git pull --rebase -v --no-edit
49 # Our local modifications remain ontop of the previously saved config.
51 # Like git stash pop (which doesn't work for new untracked files):
52 git reset --mixed HEAD^
54 # We'll see how merging works out.