git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: William Chargin <wchargin@gmail.com>
To: git@vger.kernel.org
Subject: In some rebases, `exec git -C ...` has wrong working directory
Date: Thu, 26 Apr 2018 19:56:29 -0700	[thread overview]
Message-ID: <CAFW+GMAJcCG4mKe4TxFXXrfdRhZKXv8ffC-rNShFLW2J1_FANA@mail.gmail.com> (raw)

Here is a repro script:

    #!/bin/sh
    set -eux
    git --version
    tmpdir="$(mktemp -d)"
    cd "${tmpdir}"
    mkdir target repo
    cd repo
    git init
    touch file; git add file
    git commit -m "Initial commit"
    git rebase HEAD --exec "git -C ${tmpdir}/target init"

The end of this script prints something like

    Executing: git -C /tmp/tmp.gd2q51jO93/target init
    Reinitialized existing Git repository in /tmp/tmp.gd2q51jO93/repo/.git/
    Successfully rebased and updated refs/heads/master.

But this is wrong: the repository should be initialized in `target`, not
reinitialized in `repo`.

Notes:

  - This propagates to subprocesses: if you run `exec make test` and
    your test suite ends up calling `git -C`, then the same problem
    occurs.

  - Substituting `rebase --root` for `rebase HEAD` causes the problem to
    go away.

  - The `rebase HEAD` exec context adds the `GIT_DIR` environment
    variable, and this is sufficient to reproduce the problem:
    running `GIT_DIR="$PWD" git -C /tmp/target init` puts the repo in
    the current working directory. The `rebase --root` context adds no
    such environment variable. (You can use `--exec 'env >tempfile'` to
    verify these.)

My `git --version` is 2.16.2.

             reply	other threads:[~2018-04-27  2:56 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-27  2:56 William Chargin [this message]
2018-04-27  7:45 ` In some rebases, `exec git -C ...` has wrong working directory Johannes Schindelin
2018-04-27 17:14   ` William Chargin

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=CAFW+GMAJcCG4mKe4TxFXXrfdRhZKXv8ffC-rNShFLW2J1_FANA@mail.gmail.com \
    --to=wchargin@gmail.com \
    --cc=git@vger.kernel.org \
    /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).