git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* git rebase does not understand --work-tree
@ 2010-07-14  9:04 Alexander Gladysh
  2010-07-14 12:54 ` Michael J Gruber
  0 siblings, 1 reply; 3+ messages in thread
From: Alexander Gladysh @ 2010-07-14  9:04 UTC (permalink / raw)
  To: git

Hi, list!

$ git --version
git version 1.7.1.1

I often use --work-tree and --git-dir to avoid doing cd in my scripts.

However, I've found that git rebase does not understand --work-tree
option (see test below). Is this fixable?

Thanks,
Alexander.

mkdir tmp
cd tmp
git init
echo "test">file.txt
git add .
git commit -m "initial commit"

git checkout -b other-branch
echo "test2">otherfile.txt
git add .
git commit -m "second commit"

cd ..
git --git-dir=tmp/.git --work-tree=tmp rebase other-branch

fatal: /usr/local/libexec/git-core/git-rebase cannot be used without a
working tree.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: git rebase does not understand --work-tree
  2010-07-14  9:04 git rebase does not understand --work-tree Alexander Gladysh
@ 2010-07-14 12:54 ` Michael J Gruber
  2010-07-14 12:55   ` [RFC/PATCH] am/pull/rebase/stash: cd_to_toplevel before require_work_tree Michael J Gruber
  0 siblings, 1 reply; 3+ messages in thread
From: Michael J Gruber @ 2010-07-14 12:54 UTC (permalink / raw)
  To: Alexander Gladysh; +Cc: git

Alexander Gladysh venit, vidit, dixit 14.07.2010 11:04:
> Hi, list!
> 
> $ git --version
> git version 1.7.1.1
> 
> I often use --work-tree and --git-dir to avoid doing cd in my scripts.
> 
> However, I've found that git rebase does not understand --work-tree
> option (see test below). Is this fixable?
> 
> Thanks,
> Alexander.

In your case, omitting --work-tree almost works, as well as using
"--work-tree=." (note the dot). "Almost" meaning that rebase does not
complain. It just doesn't find the work-tree.

I think the main problem here is a problem with relative work trees.

First of all, work tree is meant to be relative to (the repo specified
by) GIT_DIR, but that's not what "git rev-parse --top-level" is doing.
Experimenting with relative --git-dir and --work-tree here shows that
it's relative to cwd.

Second, several git shell commands (such as rebase) cd to the toplevel
of the repo only after checking whether we are in a work tree already.
This is brain dead and should be cured by the upcoming patch. With that,
absolute paths for work-tree will work with rebase.

Third, git's setup code exports GIT_DIR as an absolute path but
GIT_WORK_TREE as a relative path. Together with the fact that the work
tree is interpreted relative to the current directory, this is doomed
for failure when you cd around - as rebase does automatically!

I'm not sure I find time for the latter point, but until then the patch
enables you to work with absolute paths.

Michael

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [RFC/PATCH] am/pull/rebase/stash: cd_to_toplevel before require_work_tree
  2010-07-14 12:54 ` Michael J Gruber
@ 2010-07-14 12:55   ` Michael J Gruber
  0 siblings, 0 replies; 3+ messages in thread
From: Michael J Gruber @ 2010-07-14 12:55 UTC (permalink / raw)
  To: git; +Cc: Alexander Gladysh

Currently, "cd_to_toplevel" comes right after "require_work_tree" for
these commands.

Put "cd_to_toplevel" before "require_work_tree" so that these commands
do not die fatally when called with --work-tree or GIT_WORK_TREE
properly set from outside of the work tree.

Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
---
 git-am.sh     |    2 +-
 git-pull.sh   |    2 +-
 git-rebase.sh |    2 +-
 git-stash.sh  |    2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/git-am.sh b/git-am.sh
index e7f008c..bf81030 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -39,8 +39,8 @@ rebasing*       (internal use for git-rebase)"
 . git-sh-setup
 prefix=$(git rev-parse --show-prefix)
 set_reflog_action am
-require_work_tree
 cd_to_toplevel
+require_work_tree
 
 git var GIT_COMMITTER_IDENT >/dev/null ||
 	die "You need to set your committer info first"
diff --git a/git-pull.sh b/git-pull.sh
index a09a44e..83c25b9 100755
--- a/git-pull.sh
+++ b/git-pull.sh
@@ -10,8 +10,8 @@ SUBDIRECTORY_OK=Yes
 OPTIONS_SPEC=
 . git-sh-setup
 set_reflog_action "pull $*"
-require_work_tree
 cd_to_toplevel
+require_work_tree
 
 
 die_conflict () {
diff --git a/git-rebase.sh b/git-rebase.sh
index ab4afa7..96dd34f 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -31,8 +31,8 @@ SUBDIRECTORY_OK=Yes
 OPTIONS_SPEC=
 . git-sh-setup
 set_reflog_action rebase
-require_work_tree
 cd_to_toplevel
+require_work_tree
 
 LF='
 '
diff --git a/git-stash.sh b/git-stash.sh
index 1d95447..4564892 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -13,8 +13,8 @@ USAGE="list [<options>]
 SUBDIRECTORY_OK=Yes
 OPTIONS_SPEC=
 . git-sh-setup
-require_work_tree
 cd_to_toplevel
+require_work_tree
 
 TMP="$GIT_DIR/.git-stash.$$"
 trap 'rm -f "$TMP-*"' 0
-- 
1.7.2.rc1.212.g850a

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-07-14 12:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-14  9:04 git rebase does not understand --work-tree Alexander Gladysh
2010-07-14 12:54 ` Michael J Gruber
2010-07-14 12:55   ` [RFC/PATCH] am/pull/rebase/stash: cd_to_toplevel before require_work_tree Michael J Gruber

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).