# contrib/git-normal-to-bare.sh

2 messages from 2013-05-27 to 2013-05-28. Participants: Zenaan Harkness, Junio C Hamano.
Thread: https://gitlist.dev/t/33945

## Zenaan Harkness, 2013-05-27 04:54

Subject: contrib/git-normal-to-bare.sh
Message-ID: <CAOsGNST8X+crMQz1ynJQxctCMUnBw3T3K5HiMH8B_GFP63yX1w@mail.gmail.com>
URL: https://gitlist.dev/e/CAOsGNST8X%2BcrMQz1ynJQxctCMUnBw3T3K5HiMH8B_GFP63yX1w%40mail.gmail.com

```
I needed this quite a bit in the last few days, basic script but
serves my need. I think it would be useful for other beginners if in
$git/contrib/ source dir.

Just a start to a basic script. Needs more tests etc, but it's enough
to get newbies (like me) off to a reasonable start. Handles multiple
input dirs.

PLEASE CC me, as I am not subscribed.

(some SMTP server rejected attachment, so pasting below instead)

Thanks,
Zenaan


#!/bin/bash

# Change one or more normal repos into bare repos:
# See also https://git.wiki.kernel.org/index.php/GitFaq#How_do_I_make_existing_non-bare_repository_bare.3F

for i in "$@"; do
   echo; echo "----------------------"
   echo Processing $i

   repo="$i"
   repo="`basename $i`"
   tmp_repo="${repo}.git"

   # Insert here: may be exit if any spaces in repo fqn
   # Insert here: check for non-existent repo/.git dir
   # Insert here: check that we are not inside the repo
   # Insert here: add exit/do-nothing if fail to mv dirs etc

   mv $repo/.git $tmp_repo
   git --git-dir=$tmp_repo config core.bare true
   mv $repo ${repo}.bak
   mv $tmp_repo $repo
done

```

## Junio C Hamano, 2013-05-28 20:07

Subject: Re: contrib/git-normal-to-bare.sh
Message-ID: <7v1u8qzx4f.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7v1u8qzx4f.fsf%40alter.siamese.dyndns.org
In-Reply-To: <CAOsGNST8X+crMQz1ynJQxctCMUnBw3T3K5HiMH8B_GFP63yX1w@mail.gmail.com>

```
Zenaan Harkness <zen@freedbms.net> writes:

> I needed this quite a bit in the last few days, basic script but
> serves my need. I think it would be useful for other beginners if in
> $git/contrib/ source dir.
>
> Just a start to a basic script. Needs more tests etc, but it's enough
> to get newbies (like me) off to a reasonable start. Handles multiple
> input dirs.
>
> PLEASE CC me, as I am not subscribed.
>
> (some SMTP server rejected attachment, so pasting below instead)
>
> Thanks,
> Zenaan
>
>
> #!/bin/bash

I do not think you need (nor used) any bash-ism in this script.
Saying "#!/bin/sh" here is cleaner.

>
> # Change one or more normal repos into bare repos:
> # See also https://git.wiki.kernel.org/index.php/GitFaq#How_do_I_make_existing_non-bare_repository_bare.3F
>
> for i in "$@"; do

	for i
        do

You do not have to say 'in "$@"'; it is implied.

>    echo; echo "----------------------"
>    echo Processing $i

Forgot to dq?

>
>    repo="$i"
>    repo="`basename $i`"
>    tmp_repo="${repo}.git"
>    # Insert here: may be exit if any spaces in repo fqn
>    # Insert here: check for non-existent repo/.git dir
>    # Insert here: check that we are not inside the repo
>    # Insert here: add exit/do-nothing if fail to mv dirs etc
>
>    mv $repo/.git $tmp_repo

Forgot to dq?  i.e.

	mv "$repo/.git" "$tmp_repo"

The same for all the variable references in the remainder of the
script.

More importantly, "mv" would fail if $repo is given as a full
pathname elsewhere in the filesystem that is different from your
current directory where you create $tmp_repo.

>    git --git-dir=$tmp_repo config core.bare true
>    mv $repo ${repo}.bak
>    mv $tmp_repo $repo
> done

```
