add receive.denyNonFastforwards config variable
If receive.denyNonFastforwards is set to true, git-receive-pack will deny non fast-forwards, i.e. forced updates. Most notably, a push to a repository which has that flag set will fail. As a first user, 'git-init-db --shared' sets this flag, since in a shared setup, you are most unlikely to want forced pushes to succeed. Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
Johannes Schindelin committed
Sep 21, 2006 at 01:07 UTC
11031d7e9f34f6a20ff4a4bd4fa3e5e3c0024a57
5 files changed
+21
builtin-init-db.c
+1
@@ -311,6 +311,7 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
311
*/
312
sprintf(buf, "%d", shared_repository);
313
git_config_set("core.sharedrepository", buf);
314
+ git_config_set("receive.denyNonFastforwards", "true");
315
}
316
317
return 0;
cache.h
+1
@@ -188,6 +188,7 @@ extern int prefer_symlink_refs;
188
extern int log_all_ref_updates;
189
extern int warn_ambiguous_refs;
190
extern int shared_repository;
191
+extern int deny_non_fast_forwards;
192
extern const char *apply_default_whitespace;
193
extern int zlib_compression_level;
194
environment.c
+1
@@ -20,6 +20,7 @@ int warn_ambiguous_refs = 1;
20
int repository_format_version;
21
char git_commit_encoding[MAX_ENCODING_LENGTH] = "utf-8";
22
int shared_repository = PERM_UMASK;
23
+int deny_non_fast_forwards = 0;
24
const char *apply_default_whitespace;
25
int zlib_compression_level = Z_DEFAULT_COMPRESSION;
26
int pager_in_use;
receive-pack.c
+16
@@ -2,6 +2,8 @@
2
#include "refs.h"
3
#include "pkt-line.h"
4
#include "run-command.h"
5
+#include "commit.h"
6
+#include "object.h"
7
8
static const char receive_pack_usage[] = "git-receive-pack <git-dir>";
9
@@ -127,6 +129,20 @@ static int update(struct command *cmd)
129
return error("unpack should have generated %s, "
130
"but I can't find it!", new_hex);
131
}
132
+ if (deny_non_fast_forwards && !is_null_sha1(old_sha1)) {
133
+ struct commit *old_commit, *new_commit;
134
+ struct commit_list *bases;
135
+
136
+ old_commit = (struct commit *)parse_object(old_sha1);
137
+ new_commit = (struct commit *)parse_object(new_sha1);
138
+ for (bases = get_merge_bases(old_commit, new_commit, 1);
139
+ bases; bases = bases->next)
140
+ if (!hashcmp(old_sha1, bases->item->object.sha1))
141
+ break;
142
+ if (!bases)
143
+ return error("denying non-fast forward;"
144
+ " you should pull first");
145
+ }
146
safe_create_leading_directories(lock_name);
147
148
newfd = open(lock_name, O_CREAT | O_EXCL | O_WRONLY, 0666);
setup.c
+2
@@ -244,6 +244,8 @@ int check_repository_format_version(const char *var, const char *value)
244
repository_format_version = git_config_int(var, value);
245
else if (strcmp(var, "core.sharedrepository") == 0)
246
shared_repository = git_config_perm(var, value);
247
+ else if (strcmp(var, "receive.denynonfastforwards") == 0)
248
+ deny_non_fast_forwards = git_config_bool(var, value);
249
return 0;
250
}
251