From mboxrd@z Thu Jan 1 00:00:00 1970 From: Junio C Hamano Subject: Re: Behaviour of git apply --directory Date: Mon, 22 Aug 2011 11:28:08 -0700 Message-ID: <7vfwktwbbb.fsf@alter.siamese.dyndns.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: git@vger.kernel.org To: Andrew Berry X-From: git-owner@vger.kernel.org Mon Aug 22 20:28:17 2011 Return-path: Envelope-to: gcvg-git-2@lo.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1QvZEO-0005rJ-Oz for gcvg-git-2@lo.gmane.org; Mon, 22 Aug 2011 20:28:17 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752463Ab1HVS2M (ORCPT ); Mon, 22 Aug 2011 14:28:12 -0400 Received: from b-pb-sasl-quonix.pobox.com ([208.72.237.35]:46696 "EHLO smtp.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752118Ab1HVS2K (ORCPT ); Mon, 22 Aug 2011 14:28:10 -0400 Received: from smtp.pobox.com (unknown [127.0.0.1]) by b-sasl-quonix.pobox.com (Postfix) with ESMTP id 57D71405E; Mon, 22 Aug 2011 14:28:10 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=sasl; bh=twERX9Yl9wIfz7XtMynAytepi+g=; b=iNlcOR 1lrRFdeMFDP1VpfNIPwyGSG643wbXf0WyEr33JTQUpJBc9O2NuOM9V/0rqZm0EeO 1hWHaVkRF2Q8EQpaaJHaiWoa9WL2n0jszMTdtKxGrbDIgmtjNhrmLoU94jjzixVI DLhGWsh53MzBWFGxT0k+YO/mVvGvzotkmpoaI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; q=dns; s=sasl; b=yHZNTtUmi+iHTTjCVeD/TP2EDayByUhk xK1ZZWrQYLTa9N+zUSQJpPo4xP4tOvwcSUX5sMLD2bu/ptvKfnLGM19OmMtlBfjx wwdRbBTYrAdz8ViJdacmqd63x/oF8z3v1G9uXYVHnSmODghyYMciOxeP27C8ZV/y +mR2z7ZBhdE= Received: from b-pb-sasl-quonix.pobox.com (unknown [127.0.0.1]) by b-sasl-quonix.pobox.com (Postfix) with ESMTP id 4E58B405D; Mon, 22 Aug 2011 14:28:10 -0400 (EDT) Received: from pobox.com (unknown [76.102.170.102]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by b-sasl-quonix.pobox.com (Postfix) with ESMTPSA id B92AA405C; Mon, 22 Aug 2011 14:28:09 -0400 (EDT) In-Reply-To: (Andrew Berry's message of "Mon, 22 Aug 2011 11:21:55 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) X-Pobox-Relay-ID: 7CB4CD42-CCEC-11E0-B63D-1DC62E706CDE-77302942!b-pb-sasl-quonix.pobox.com Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: Andrew Berry writes: > The behaviour of git apply --directory seems a little confusing. It > looks to be dependent on the current directory, but I can't use relative > paths to apply a patch in one directory to a sibling directory. Absolute > paths don't work either. I'd expected the parameter to either be > relative to the git repository root, or to expand relative directories. I do not think that parameter does not have anything to do with your cwd. As the documentation says: --directory=:: Prepend to all filenames. If a "-p" argument was also passed, it is applied before prepending the new root. For example, a patch that talks about updating `a/git-gui.sh` to `b/git-gui.sh` can be applied to the file in the working tree `modules/git-gui/git-gui.sh` by running `git apply --directory=modules/git-gui`. the parameter is just a fixed string that is used to modify the path that appears in the patch before it gets applied, and has nothing to do with your current (or previous for that matter) working directory. Suppose you have a patch that tries to update "COPYING". Such a patch generated by Git would look like this: diff --git a/COPYING b/COPYING index 536e555..ee559b1 100644 --- a/COPYING +++ b/COPYING @@ -1,3 +1,4 @@ +GPL GPL GPL Note that the only valid version of the GPL as far as this project is concerned is _this_ particular version of the license (ie v2, not Further suppose that you have already rearranged your project so that that file appears in licenses/gpl directory, and your $(cwd) is licenses/ subdirectory of your working tree. You would give --directory=licenses/gpl/ without passing any custom -p parameter. This internally turns the patch being applied into something like: diff --git a/licenses/gpl/COPYING b/licenses/gpl/COPYING index 536e555..ee559b1 100644 --- a/licenses/gpl/COPYING +++ b/licenses/gpl/COPYING @@ -1,3 +1,4 @@ +GPL GPL GPL Note that the only valid version of the GPL as far as this project is concerned is _this_ particular version of the license (ie v2, not Because the patch application in git is always relative to the top level of your working tree no matter where you are, this applies to the path you intended it to. Here is a sample transcript to try it yourself. $ (echo GPL GPL GPL; cat COPYING) >x && cat x >COPYING $ git diff >P.diff $ git checkout COPYING $ mkdir -p licenses/gpl $ git mv COPYING licenses/gpl $ cd licenses $ git apply -v --directory=licenses/gpl ../P.diff Checking patch licenses/gpl/COPYING... Applied patch licenses/gpl/COPYING cleanly. $ git diff diff --git a/licenses/gpl/COPYING b/licenses/gpl/COPYING index 536e555..ee559b1 100644 --- a/licenses/gpl/COPYING +++ b/licenses/gpl/COPYING @@ -1,3 +1,4 @@ +GPL GPL GPL Note that the only valid version of the GPL as far as this project is concerned is _this_ particular version of the license (ie v2, not