From: Stephen Bash <bash@genarts.com>
To: Jeff King <peff@peff.net>
Cc: Git Mailing List <git@vger.kernel.org>,
Sitaram Chamarty <sitaramc@gmail.com>
Subject: Re: can we prevent reflog deletion when branch is deleted?
Date: Thu, 14 Nov 2013 09:42:36 -0500 (EST) [thread overview]
Message-ID: <2137000803.2895009.1384440156683.JavaMail.root@genarts.com> (raw)
In-Reply-To: <20131114081456.GC16327@sigill.intra.peff.net>
----- Original Message -----
> From: "Jeff King" <peff@peff.net>
> Sent: Thursday, November 14, 2013 3:14:56 AM
> Subject: Re: can we prevent reflog deletion when branch is deleted?
>
> On Thu, Nov 14, 2013 at 05:48:50AM +0530, Sitaram Chamarty wrote:
>
> > Is there *any* way we can preserve a reflog for a deleted branch,
> > perhaps under logs/refs/deleted/<timestamp>/full/ref/name ?
>
> At GitHub, we log each change to an "audit log" in addition to the
> regular reflog (we also stuff extra data from the environment into the
> reflog message). So even after a branch is deleted, its audit log
> entries remain, though you have to pull out the data by hand (git
> doesn't know about it at all, except as an append-only sink for
> writing).
We recently ran into a similar situation at my $dayjob, so I made our
server side update hook log all pushes (including deletes) and added the
new log file to logrotate(8) -- note: make sure if logrotate recreates
the file that it allows everyone to write to it. I'm sure it's not as
comprehensive as Peff's solution, but it's pretty simple for smaller
shops that want a little more protection. Here are the relevant
excerpts from the script:
#!/usr/bin/env python
import os, sys, pwd, stat
from datetime import datetime
def log_push(too_many_changes):
log_file = 'push-log.txt'
try:
f = open(log_file, 'a')
try:
# In case we just created the file, attempt to chmod it
os.chmod(log_file, 0666)
except OSError:
# chmod will fail if the current user isn't the owner, but
# if we've gotten this far we already have write permissions,
# so just continue quietly
pass
# Linux/Mac okay, bad for Windows
username = pwd.getpwuid(os.getuid())[0]
f.write('%s: %s push by %s of %s from %s to %s\n'% \
(datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
'Failed' if too_many_changes else 'Successful', username,
refname, oldsha, newsha))
f.close()
except IOError:
try:
log_stats = os.stat(log_file)
# Figure out owner and permissions
log_owner = pwd.getpwuid(log_stats.st_uid).pw_name
log_perm = oct(stat.S_IMODE(log_stats.st_mode))
print_flush('Unable to open %s for appending. Current owner ' + \
'is %s and permissions are %s.'%(log_file,
log_owner, log_perm))
except:
exception,desc,stack = sys.exc_info()
print_flush('Unable to open log file. While generating error' + \
' message encountered error: %s'%(desc))
if len(sys.argv) != 4:
print_flush('Usage: %s refname oldsha newsha'%sys.argv[0])
sys.exit(1)
refname = sys.argv[1]
oldsha = sys.argv[2]
newsha = sys.argv[3]
if newsha == '0'*40:
# Deleted ref, nothing to do
log_push(False)
sys.exit(0)
# ... checking for various rule/style violations ...
log_push(too_many_changes)
if too_many_changes:
sys.exit(1)
else:
sys.exit(0)
next prev parent reply other threads:[~2013-11-14 14:42 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-01 1:31 can we prevent reflog deletion when branch is deleted? Sitaram Chamarty
2013-06-01 3:00 ` Michael Haggerty
2013-06-01 5:03 ` Jeff King
2013-06-01 7:59 ` Ramkumar Ramachandra
2013-06-01 9:09 ` Jeff King
2013-06-01 9:47 ` Ramkumar Ramachandra
2013-06-01 17:25 ` Sitaram Chamarty
2013-06-01 17:56 ` Ramkumar Ramachandra
2013-06-02 10:20 ` Sitaram Chamarty
2013-11-14 0:18 ` Sitaram Chamarty
2013-11-14 7:56 ` Thomas Rast
2013-11-14 8:07 ` Jeff King
2013-11-14 10:56 ` Sitaram Chamarty
2013-11-14 11:09 ` Jeff King
2013-11-14 11:17 ` Luca Milanesio
2013-11-14 13:48 ` Sitaram Chamarty
2013-11-14 13:47 ` Sitaram Chamarty
2013-11-14 8:14 ` Jeff King
2013-11-14 14:42 ` Stephen Bash [this message]
2013-11-14 16:20 ` Sitaram Chamarty
2013-11-14 16:06 ` Sitaram Chamarty
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=2137000803.2895009.1384440156683.JavaMail.root@genarts.com \
--to=bash@genarts.com \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
--cc=sitaramc@gmail.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 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).