git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Richard Hartmann <richih.mailinglist@gmail.com>
To: Jonathan Nieder <jrnieder@gmail.com>
Cc: Git List <git@vger.kernel.org>
Subject: Re: Cloning into an existing, non-empty directory?
Date: Fri, 22 Apr 2011 13:21:42 +0200	[thread overview]
Message-ID: <BANLkTikY7c7rP+yv5vt2vxw5nu84k_H=Xw@mail.gmail.com> (raw)
In-Reply-To: <20110421220327.GA3396@elie>

On Fri, Apr 22, 2011 at 00:03, Jonathan Nieder <jrnieder@gmail.com> 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

  reply	other threads:[~2011-04-22 11:22 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-21 21:27 Cloning into an existing, non-empty directory? Richard Hartmann
2011-04-21 22:03 ` Jonathan Nieder
2011-04-22 11:21   ` Richard Hartmann [this message]
2011-04-23 10:15     ` Jonathan Nieder
2011-04-23 10:28       ` Nguyen Thai Ngoc Duy
2011-04-23 10:37         ` Jonathan Nieder
2011-04-23 22:11       ` Richard Hartmann
2011-04-25  8:00         ` Jonathan Nieder
2011-04-25  8:40           ` Andreas Schwab
2011-04-25  8:59             ` Jonathan Nieder
2011-04-25 18:37               ` Jeff King
2011-04-25 14:08           ` Richard Hartmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='BANLkTikY7c7rP+yv5vt2vxw5nu84k_H=Xw@mail.gmail.com' \
    --to=richih.mailinglist@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=jrnieder@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).