Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2016-01-06 16:09:43 +0300
committerJunio C Hamano <gitster@pobox.com>2016-01-08 00:52:55 +0300
commit79d7582e32ca84eacf032298c8ae3d26816f48d0 (patch)
tree370b19ccf775725f0a2a28e21e7443b330dffe1a
parent833e48259e23aea76f3765d28d1b2200332301f7 (diff)
commit: allow editing the commit message even in shared repos
It was pointed out by Yaroslav Halchenko that the file containing the commit message is writable only by the owner, which means that we have to rewrite it from scratch in a shared repository. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--builtin/commit.c2
-rw-r--r--git-compat-util.h1
-rw-r--r--wrapper.c13
3 files changed, 15 insertions, 1 deletions
diff --git a/builtin/commit.c b/builtin/commit.c
index f2a8b78c7a..ce11a17f8a 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -761,7 +761,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
hook_arg2 = "";
}
- s->fp = fopen(git_path(commit_editmsg), "w");
+ s->fp = fopen_for_writing(git_path(commit_editmsg));
if (s->fp == NULL)
die_errno(_("could not open '%s'"), git_path(commit_editmsg));
diff --git a/git-compat-util.h b/git-compat-util.h
index 0feeae2983..d98f3af5e7 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -733,6 +733,7 @@ extern int xmkstemp_mode(char *template, int mode);
extern int odb_mkstemp(char *template, size_t limit, const char *pattern);
extern int odb_pack_keep(char *name, size_t namesz, const unsigned char *sha1);
extern char *xgetcwd(void);
+extern FILE *fopen_for_writing(const char *path);
#define REALLOC_ARRAY(x, alloc) (x) = xrealloc((x), (alloc) * sizeof(*(x)))
diff --git a/wrapper.c b/wrapper.c
index dae5675a96..371a7f0b63 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -375,6 +375,19 @@ FILE *xfdopen(int fd, const char *mode)
return stream;
}
+FILE *fopen_for_writing(const char *path)
+{
+ FILE *ret = fopen(path, "w");
+
+ if (!ret && errno == EPERM) {
+ if (!unlink(path))
+ ret = fopen(path, "w");
+ else
+ errno = EPERM;
+ }
+ return ret;
+}
+
int xmkstemp(char *template)
{
int fd;