restore: Implemented with stash. (Does not work for adding untracked files.)
[gitgitconfig.git] / gitgitconfig-restore
blob65d35eecaa675a6e85564e1fc31f1ef4ed74aa7f
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 git stash --include-untracked
42 # Pulling from GITCONFIG/master in origin:
43 # (We have set up such behavior in our gitgitconfig-init.)
44 git pull --rebase -v --no-edit
45 # Our local modifications remain ontop of the previously saved config.
46 git stash pop
48 # We'll see how merging works out.