Re: Cloning into an existing, non-empty directory?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Apr 22, 2011 at 00:03, Jonathan Nieder <jrnieder@xxxxxxxxx> wrote:

> Have you tried something like the following?

I didn't. Thanks a lot for your feedback.

My tentative script, which is pretty ham-fisted, takes care of most
(all?) possible errors, feedback on it is very welcome.

Two issues remain, though:

1) git merge does not seem to understand either of those parameters.
This means that I have to pull, not merge, which introduces a race
condition into my safety checks. Which leads me to

2) running `git pull` as suggested results in:

fatal: /usr/lib/git-core/git-pull cannot be used without a working tree.

which can be worked around by using --work-tree and --git-dir . Not
ideal, but workeable if I accept the race condition.




#!/bin/sh
set -x

[[ $# -lt 2 ]] && echo "not enough arguments" && exit 1
[[ $# -eq 2 ]] && GIT_WORK_TREE="$HOME/killme/fgit/target-default"
[[ $# -eq 3 ]] && GIT_WORK_TREE="$3"
[[ $# -gt 3 ]] && echo "too many arguments" && exit 2

GIT_REMOTE="$1"
GIT_DIR="$2"
export GIT_REMOTE GIT_DIR GIT_WORK_TREE
mkdir -p $GIT_WORK_TREE
cd $GIT_WORK_TREE ||
  (echo "$(basename $0): fatal: could not enter $GIT_WORK_TREE" &&
   exit 20) || exit 20
git init
git remote add origin $GIT_REMOTE
git config branch.master.remote origin
git config branch.master.merge  refs/heads/master
git fetch
for i in $(git ls-tree -r origin/master | awk '{print $4}'); do
	[[ -e $i ]] &&
	  echo "$(basename $0): error: $i exists." &&
	  CONFLICT=1;
done

[[ -n $CONFLICT ]] &&
  echo "$(basename $0): Will stop after fetching and not try to merge!\n" &&
  exit 3

git --work-tree="$GIT_WORK_TREE" --git-dir="$GIT_DIR" pull
#git --work-tree="$GIT_WORK_TREE" --git-dir="$GIT_DIR" merge


As usual, any and all feedback appreciated,
thanks,
Richard
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]