{"thread":{"id":"15915","subject":"[PATCH] Preserve file permissions on git-reflog expire","startedAt":"2008-10-15T17:34:58Z","lastAt":"2008-10-16T12:34:45Z","messageCount":3,"participants":["Samuel Lucas Vaz de Mello","Junio C Hamano","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"93110","messageId":"48F629C2.70203@datacom.ind.br","threadId":"15915","inReplyTo":null,"subject":"[PATCH] Preserve file permissions on git-reflog expire","fromName":"Samuel Lucas Vaz de Mello","fromEmail":"samuellucas@datacom.ind.br","sentAt":"2008-10-15T17:34:58Z","receivedAt":"2008-10-15T17:34:58Z","isPatch":true,"sender":{"key":"samuellucas@datacom.ind.br","avatar":null},"body":"Preserve file permissions on git-reflog expire to avoid problems with shared repositories and git-gc.\n\nSigned-off-by: Samuel Lucas Vaz de Mello <samuellucas@datacom.ind.br>\n\n---\n\nThis small patch fixes a bug with shared repositories and git-reflog expire.\nIf you have a shared repository created with git-init --shared, several users can push to it.\nOnce you run git-gc (which calls git-reflog expire) on the shared repository, the reflogs files are recreated with umask permissions, which defaults to 644 (with no group write). Since then, users receive the following error when trying to push:\n\nsamuel@erdinger:~/myrepo$ git push \nCounting objects: 5, done.\nCompressing objects: 100% (3/3), done.\nUnpacking objects: 100% (3/3), done.\nWriting objects: 100% (3/3), 295 bytes, done.\nTotal 3 (delta 2), reused 0 (delta 0)\nerror: Unable to append to logs/refs/heads/master: Permission denied \nTo /remote/myrepo/\n! [remote rejected] master -> master (failed to write)\nerror: failed to push some refs to '/remote/myrepo/' \n\nThis patch avoid this error preserving the permissions on reflog files.\n\n builtin-reflog.c |    5 +++++\n 1 files changed, 5 insertions(+), 0 deletions(-)\n\ndiff --git a/builtin-reflog.c b/builtin-reflog.c\nindex 6b3667e..92a0d53 100644\n--- a/builtin-reflog.c\n+++ b/builtin-reflog.c\n@@ -265,6 +265,7 @@ static int expire_reflog(const char *ref, const unsigned char *sha1, int unused,\n \tstruct cmd_reflog_expire_cb *cmd = cb_data;\n \tstruct expire_reflog_cb cb;\n \tstruct ref_lock *lock;\n+\tstruct stat filestat;\n \tchar *log_file, *newlog_path = NULL;\n \tint status = 0;\n \n@@ -303,6 +304,10 @@ static int expire_reflog(const char *ref, const unsigned char *sha1, int unused,\n \t\t\tstatus |= error(\"Couldn't write %s\",\n \t\t\t\tlock->lk->filename);\n \t\t\tunlink(newlog_path);\n+\t\t} else if (stat(log_file, &filestat)){\n+\t\t\tstatus |= error(\"unable to read permissions of %s\", log_file);\n+\t\t} else if (chmod(newlog_path, filestat.st_mode)){\n+\t\t\tstatus |= error(\"cannot set permissions of %s\", newlog_path);\n \t\t} else if (rename(newlog_path, log_file)) {\n \t\t\tstatus |= error(\"cannot rename %s to %s\",\n \t\t\t\t\tnewlog_path, log_file);\n-- \n1.6.0.2.532.g84ed4c.dirty\n"},{"id":"93111","messageId":"7v3aix4ud4.fsf@gitster.siamese.dyndns.org","threadId":"15915","inReplyTo":"48F629C2.70203@datacom.ind.br","subject":"Re: [PATCH] Preserve file permissions on git-reflog expire","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-10-15T17:54:15Z","receivedAt":"2008-10-15T17:54:15Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Samuel Lucas Vaz de Mello <samuellucas@datacom.ind.br> writes:\n\n> Preserve file permissions on git-reflog expire to avoid problems with shared repositories and git-gc.\n\nLooong line needs wrapped (I could do this myself if this was the only\nissue, but...)\n\n> Signed-off-by: Samuel Lucas Vaz de Mello <samuellucas@datacom.ind.br>\n>\n> ---\n>\n> This small patch fixes a bug with shared repositories and git-reflog expire.\n\n> samuel@erdinger:~/myrepo$ git push \n> Counting objects: 5, done.\n> Compressing objects: 100% (3/3), done.\n> Unpacking objects: 100% (3/3), done.\n> Writing objects: 100% (3/3), 295 bytes, done.\n> Total 3 (delta 2), reused 0 (delta 0)\n> error: Unable to append to logs/refs/heads/master: Permission denied \n> To /remote/myrepo/\n> ! [remote rejected] master -> master (failed to write)\n> error: failed to push some refs to '/remote/myrepo/' \n\nThanks for a reproduction recipe.  I think an abbreviated version of this\nwould deserve to be in the commit log message proper.\n\n> diff --git a/builtin-reflog.c b/builtin-reflog.c\n> index 6b3667e..92a0d53 100644\n> --- a/builtin-reflog.c\n> +++ b/builtin-reflog.c\n> @@ -265,6 +265,7 @@ static int expire_reflog(const char *ref, const unsigned char *sha1, int unused,\n>  \tstruct cmd_reflog_expire_cb *cmd = cb_data;\n>  \tstruct expire_reflog_cb cb;\n>  \tstruct ref_lock *lock;\n> +\tstruct stat filestat;\n>  \tchar *log_file, *newlog_path = NULL;\n>  \tint status = 0;\n>  \n> @@ -303,6 +304,10 @@ static int expire_reflog(const char *ref, const unsigned char *sha1, int unused,\n>  \t\t\tstatus |= error(\"Couldn't write %s\",\n>  \t\t\t\tlock->lk->filename);\n>  \t\t\tunlink(newlog_path);\n> +\t\t} else if (stat(log_file, &filestat)){\n> +\t\t\tstatus |= error(\"unable to read permissions of %s\", log_file);\n\nHmmm.  Is there a reason you did not use adjust_shared_perm() like all the\nother codepaths for creating files under .git/ directory do?\n"},{"id":"93194","messageId":"alpine.DEB.1.00.0810161434220.22125@pacific.mpi-cbg.de.mpi-cbg.de","threadId":"15915","inReplyTo":"7v3aix4ud4.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] Preserve file permissions on git-reflog expire","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-10-16T12:34:45Z","receivedAt":"2008-10-16T12:34:45Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Wed, 15 Oct 2008, Junio C Hamano wrote:\n\n> Samuel Lucas Vaz de Mello <samuellucas@datacom.ind.br> writes:\n> \n> > samuel@erdinger:~/myrepo$ git push \n> > Counting objects: 5, done.\n> > Compressing objects: 100% (3/3), done.\n> > Unpacking objects: 100% (3/3), done.\n> > Writing objects: 100% (3/3), 295 bytes, done.\n> > Total 3 (delta 2), reused 0 (delta 0)\n> > error: Unable to append to logs/refs/heads/master: Permission denied \n> > To /remote/myrepo/\n> > ! [remote rejected] master -> master (failed to write)\n> > error: failed to push some refs to '/remote/myrepo/' \n> \n> Thanks for a reproduction recipe.  I think an abbreviated version of this\n> would deserve to be in the commit log message proper.\n\nOr as a test script.\n\nCiao,\nDscho\n"}]}