git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Richard Hartmann <richih.mailinglist@gmail.com>
Date
Apr 22, 2011, 11:21 UTC
Message-ID
<BANLkTikY7c7rP+yv5vt2vxw5nu84k_H=Xw@mail.gmail.com>
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

Previous: Jonathan NiederNext: Jonathan Nieder
Message 3 of 12 in “Cloning into an existing, non-empty directory?”
  1. Richard HartmannApr 21, 2011
  2. Jonathan NiederApr 21, 2011
  3. Richard HartmannApr 22, 2011
  4. Jonathan NiederApr 23, 2011
  5. Nguyen Thai Ngoc DuyApr 23, 2011
  6. Jonathan NiederApr 23, 2011
  7. Richard HartmannApr 23, 2011
  8. Jonathan NiederApr 25, 2011
  9. Andreas SchwabApr 25, 2011
  10. Jonathan NiederApr 25, 2011
  11. Jeff KingApr 25, 2011
  12. Richard HartmannApr 25, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.