Skip to content

Commit e861ce1

Browse files
author
Junio C Hamano
committed
Merge branch 'jc/bare'
* jc/bare: Disallow working directory commands in a bare repository. git-fetch: allow updating the current branch in a bare repository. Introduce is_bare_repository() and core.bare configuration variable Move initialization of log_all_ref_updates
2 parents 141d21b + 7eff28a commit e861ce1

17 files changed

+62
-15
lines changed

builtin-init-db.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,13 @@ static int create_default_files(const char *git_dir, const char *template_path)
252252
}
253253
git_config_set("core.filemode", filemode ? "true" : "false");
254254

255-
/* Enable logAllRefUpdates if a working tree is attached */
256-
if (!is_bare_git_dir(git_dir))
255+
if (is_bare_repository()) {
256+
git_config_set("core.bare", "true");
257+
}
258+
else {
259+
git_config_set("core.bare", "false");
257260
git_config_set("core.logallrefupdates", "true");
261+
}
258262
return reinit;
259263
}
260264

cache.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ extern int cache_errno;
127127
#define CONFIG_LOCAL_ENVIRONMENT "GIT_CONFIG_LOCAL"
128128
#define EXEC_PATH_ENVIRONMENT "GIT_EXEC_PATH"
129129

130-
extern int is_bare_git_dir(const char *dir);
130+
extern int is_bare_repository_cfg;
131+
extern int is_bare_repository(void);
131132
extern const char *get_git_dir(void);
132133
extern char *get_object_directory(void);
133134
extern char *get_refs_directory(void);

config.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,11 @@ int git_default_config(const char *var, const char *value)
269269
return 0;
270270
}
271271

272+
if (!strcmp(var, "core.bare")) {
273+
is_bare_repository_cfg = git_config_bool(var, value);
274+
return 0;
275+
}
276+
272277
if (!strcmp(var, "core.ignorestat")) {
273278
assume_unchanged = git_config_bool(var, value);
274279
return 0;

environment.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ int use_legacy_headers = 1;
1515
int trust_executable_bit = 1;
1616
int assume_unchanged;
1717
int prefer_symlink_refs;
18-
int log_all_ref_updates;
18+
int is_bare_repository_cfg = -1; /* unspecified */
19+
int log_all_ref_updates = -1; /* unspecified */
1920
int warn_ambiguous_refs = 1;
2021
int repository_format_version;
2122
char *git_commit_encoding;
@@ -51,12 +52,15 @@ static void setup_git_env(void)
5152
git_graft_file = getenv(GRAFT_ENVIRONMENT);
5253
if (!git_graft_file)
5354
git_graft_file = xstrdup(git_path("info/grafts"));
54-
log_all_ref_updates = !is_bare_git_dir(git_dir);
5555
}
5656

57-
int is_bare_git_dir (const char *dir)
57+
int is_bare_repository(void)
5858
{
59-
const char *s;
59+
const char *dir, *s;
60+
if (0 <= is_bare_repository_cfg)
61+
return is_bare_repository_cfg;
62+
63+
dir = get_git_dir();
6064
if (!strcmp(dir, DEFAULT_GIT_DIR_ENVIRONMENT))
6165
return 0;
6266
s = strrchr(dir, '/');

git-am.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ USAGE='[--signoff] [--dotest=<dir>] [--utf8 | --no-utf8] [--binary] [--3way]
77
or, when resuming [--skip | --resolved]'
88
. git-sh-setup
99
set_reflog_action am
10+
require_work_tree
1011

1112
git var GIT_COMMITTER_IDENT >/dev/null || exit
1213

git-checkout.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
USAGE='[-f] [-b <new_branch>] [-m] [<branch>] [<paths>...]'
44
SUBDIRECTORY_OK=Sometimes
55
. git-sh-setup
6+
require_work_tree
67

78
old_name=HEAD
89
old=$(git-rev-parse --verify $old_name 2>/dev/null)

git-clean.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ When optional <paths>... arguments are given, the paths
1414
affected are further limited to those that match them.'
1515
SUBDIRECTORY_OK=Yes
1616
. git-sh-setup
17+
require_work_tree
1718

1819
ignored=
1920
ignoredonly=

git-commit.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
USAGE='[-a] [-s] [-v] [--no-verify] [-m <message> | -F <logfile> | (-C|-c) <commit>] [-u] [--amend] [-e] [--author <author>] [[-i | -o] <path>...]'
77
SUBDIRECTORY_OK=Yes
88
. git-sh-setup
9+
require_work_tree
910

1011
git-rev-parse --verify HEAD >/dev/null 2>&1 || initial_commit=t
1112

git-fetch.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,12 @@ update_local_ref () {
231231
esac
232232
}
233233

234-
case "$update_head_ok" in
235-
'')
234+
# updating the current HEAD with git-fetch in a bare
235+
# repository is always fine.
236+
if test -z "$update_head_ok" && test $(is_bare_repository) = false
237+
then
236238
orig_head=$(git-rev-parse --verify HEAD 2>/dev/null)
237-
;;
238-
esac
239+
fi
239240

240241
# If --tags (and later --heads or --all) is specified, then we are
241242
# not talking about defaults stored in Pull: line of remotes or

git-merge.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ USAGE='[-n] [--no-commit] [--squash] [-s <strategy>] [-m=<merge-message>] <commi
77

88
. git-sh-setup
99
set_reflog_action "merge $*"
10+
require_work_tree
1011

1112
test -z "$(git ls-files -u)" ||
1213
die "You are in a middle of conflicted merge."

0 commit comments

Comments
 (0)