All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Aleksander Boruch-Gruszecki <aleksander.boruchgruszecki@gmail.com>
Cc: Duy Nguyen <pclouds@gmail.com>,
	Git Mailing List <git@vger.kernel.org>,
	Stefan Beller <stefanbeller@googlemail.com>
Subject: Re: [PATCH v2] merge-file: correctly open files when in a subdir
Date: Wed, 11 Feb 2015 11:02:45 -0800	[thread overview]
Message-ID: <xmqqtwystgoa.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <xmqqd25gux4r.fsf@gitster.dls.corp.google.com> (Junio C. Hamano's message of "Wed, 11 Feb 2015 10:21:56 -0800")

Junio C Hamano <gitster@pobox.com> writes:

> Thanks, that makes sense and it also makes sense that checking the
> resulting content in dir/a.txt would make sense.  Then we many not
> need to add a new dir/deep/* test---after all they are checking the
> same thing.

Here is what I have right now, queued somewhere in 'pu', after
fixing it up a bit.

-- >8 --
From: Aleksander Boruch-Gruszecki <aleksander.boruchgruszecki@gmail.com>
Date: Sun, 8 Feb 2015 17:53:53 +0100
Subject: [PATCH] merge-file: correctly open files when in a subdir

run_setup_gently() is called before merge-file. This may result in changing
current working directory, which wasn't taken into account when opening a file
for writing.

Fix by prepending the passed prefix. Previous var is left so that error
messages keep referring to the file from the user's working directory
perspective.

Signed-off-by: Aleksander Boruch-Gruszecki <aleksander.boruchgruszecki@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin/merge-file.c  | 3 ++-
 t/t6023-merge-file.sh | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/builtin/merge-file.c b/builtin/merge-file.c
index 844f84f..232b768 100644
--- a/builtin/merge-file.c
+++ b/builtin/merge-file.c
@@ -90,7 +90,8 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)
 
 	if (ret >= 0) {
 		const char *filename = argv[0];
-		FILE *f = to_stdout ? stdout : fopen(filename, "wb");
+		const char *fpath = prefix_filename(prefix, prefixlen, argv[0]);
+		FILE *f = to_stdout ? stdout : fopen(fpath, "wb");
 
 		if (!f)
 			ret = error("Could not open %s for writing", filename);
diff --git a/t/t6023-merge-file.sh b/t/t6023-merge-file.sh
index 432f086..d0df869 100755
--- a/t/t6023-merge-file.sh
+++ b/t/t6023-merge-file.sh
@@ -69,7 +69,8 @@ test_expect_success 'works in subdirectory' '
 	cp new1.txt dir/a.txt &&
 	cp orig.txt dir/o.txt &&
 	cp new2.txt dir/b.txt &&
-	( cd dir && git merge-file a.txt o.txt b.txt )
+	( cd dir && git merge-file a.txt o.txt b.txt ) &&
+	test_path_is_missing a.txt
 '
 
 cp new1.txt test.txt
-- 
2.3.0-185-g073f588

  reply	other threads:[~2015-02-11 19:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-10 20:23 [PATCH v2] merge-file: correctly open files when in a subdir Aleksander Boruch-Gruszecki
2015-02-10 20:57 ` Junio C Hamano
2015-02-11  9:58   ` Aleksander Boruch-Gruszecki
2015-02-11 18:21     ` Junio C Hamano
2015-02-11 19:02       ` Junio C Hamano [this message]
2015-02-11 21:20         ` Aleksander Boruch-Gruszecki

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=xmqqtwystgoa.fsf@gitster.dls.corp.google.com \
    --to=gitster@pobox.com \
    --cc=aleksander.boruchgruszecki@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=pclouds@gmail.com \
    --cc=stefanbeller@googlemail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.