git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* git-checkout and SUBDIRECTORY_OK='Yes'
@ 2005-12-23  4:20 Jon Nelson
  2005-12-23  4:58 ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Jon Nelson @ 2005-12-23  4:20 UTC (permalink / raw)
  To: git


Is it safe to set SUBDIRECTORY_OK='Yes' in git-checkout.sh?
What about the other *.sh that don't already set it?

--
Jon Nelson <jnelson-git@jamponi.net>

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

* Re: git-checkout and SUBDIRECTORY_OK='Yes'
  2005-12-23  4:20 git-checkout and SUBDIRECTORY_OK='Yes' Jon Nelson
@ 2005-12-23  4:58 ` Junio C Hamano
  2005-12-23 17:56   ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2005-12-23  4:58 UTC (permalink / raw)
  To: Jon Nelson; +Cc: git

Jon Nelson <jnelson-git@jamponi.net> writes:

> Is it safe to set SUBDIRECTORY_OK='Yes' in git-checkout.sh?

Personally, I do not like this kind of question. If it were
known to be safe we would have set it so already.

Ah, I must be tired.  Sorry.  Let's try again.

git-checkout does two very different things, and what they
should do when run from subdirectory are probably quite
different.

It does not make any sense to run the one that switches the
current head from anywhere other than the toplevel:

	git-checkout [-f] <branch>
        git-checkout [-b <branch>] <committish>

We could of course chdir to top and do the whole-tree checkout
in git-checkout, but the point is the operation does not make
sense on a partial tree.

The other form is to update the index file and working tree file
selectively:

	git-checkout <treeish> <file>... ;# out of tree to index and file
        git-checkout -- <file>...	 ;# out of index to file

This form _does_ make sense to run from subdirectory; and I
myself often wish we supported this.

Before SUBDIRECTORY_OK was introduced, git-*.sh commands were
carefully inspected and the ones that do not make much sense to
be run in subdirectories were marked with sh-setup.  So if you
do not see SUBDIRECTORY_OK, it is very likely that you need some
real work (like the analysis above to think what should happen
when run from a subdirectory, and actually coding it).

This patch *might* work, or it may not.  Please let us know.


diff --git a/git-checkout.sh b/git-checkout.sh
index 36308d2..1219ea0 100755
--- a/git-checkout.sh
+++ b/git-checkout.sh
@@ -1,6 +1,7 @@
 #!/bin/sh
 
 USAGE='[-f] [-b <new_branch>] [<branch>] [<paths>...]'
+SUBDIRECTORY_OK=Sometimes
 . git-sh-setup
 
 old=$(git-rev-parse HEAD)
@@ -95,6 +96,14 @@ else
 	fi
 fi
 
+# We are switching branches and checking out trees, so
+# we *NEED* to be at the toplevel.
+cdup=$(git-rev-parse --show-cdup)
+if test ! -z "$cdup"
+then
+	cd "$cdup"
+fi
+
 [ -z "$new" ] && new=$old
 
 # If we don't have an old branch that we're switching to,
diff --git a/rev-parse.c b/rev-parse.c
index bb4949a..0c951af 100644
--- a/rev-parse.c
+++ b/rev-parse.c
@@ -216,6 +216,18 @@ int main(int argc, char **argv)
 					puts(prefix);
 				continue;
 			}
+			if (!strcmp(arg, "--show-cdup")) {
+				const char *pfx = prefix;
+				while (pfx) {
+					pfx = strchr(pfx, '/');
+					if (pfx) {
+						pfx++;
+						printf("../");
+					}
+				}
+				putchar('\n');
+				continue;
+			}
 			if (!strcmp(arg, "--git-dir")) {
 				const char *gitdir = getenv(GIT_DIR_ENVIRONMENT);
 				static char cwd[PATH_MAX];

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

* Re: git-checkout and SUBDIRECTORY_OK='Yes'
  2005-12-23  4:58 ` Junio C Hamano
@ 2005-12-23 17:56   ` Junio C Hamano
  0 siblings, 0 replies; 3+ messages in thread
From: Junio C Hamano @ 2005-12-23 17:56 UTC (permalink / raw)
  To: git; +Cc: Jon Nelson

Junio C Hamano <junkio@cox.net> writes:

> Jon Nelson <jnelson-git@jamponi.net> writes:
>
>> Is it safe to set SUBDIRECTORY_OK='Yes' in git-checkout.sh?

> This patch *might* work, or it may not...

I've done some tests and it seems to work (it is in the
proposed updates branch).

In git.git working tree, here is what happens:

	$ git checkout pu			;# start from pu
        $ cd Documentation
        $ echo >>git-daemon.txt			;# smudge
        $ git checkout -- git-daemon.txt	;# restore
	$ git diff -r --name-status		;# no change
        $ git checkout master git-daemon.txt	;# pick from tree
	$ git diff master -r --name-status	;# (1)
	$ git diff -r --name-status		;# (2)
	$ git diff pu -r --name-status          ;# (3)
        M	Documentation/git-daemon.txt

    (1) does not show any because it did take the file out of master
        branch, and git-daemon.txt is the only file different under
        Documentation/ between master and pu.

    (2) does not show any because "checkout master git-daemon.txt"
        updated the path both in index and working tree.

    (3) shows the path indeed is different between master and pu.

The change relies on ls-tree showing full paths regardless of
where it gets started (because the output is fed to --index-info
form of git-update-index).  If we are going to take the "ls-tree
prefix truncation" patch from Linus, either we also need to
update "git-update-index --index-info" to match this.

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

end of thread, other threads:[~2005-12-23 17:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-12-23  4:20 git-checkout and SUBDIRECTORY_OK='Yes' Jon Nelson
2005-12-23  4:58 ` Junio C Hamano
2005-12-23 17:56   ` Junio C Hamano

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