add: add --chmod=+x / --chmod=-x options
The executable bit will not be detected (and therefore will not be set) for paths in a repository with `core.filemode` set to false, though the users may still wish to add files as executable for compatibility with other users who _do_ have `core.filemode` functionality. For example, Windows users adding shell scripts may wish to add them as executable for compatibility with users on non-Windows. Although this can be done with a plumbing command (`git update-index --add --chmod=+x foo`), teaching the `git-add` command allows users to set a file executable with a command that they're already familiar with. Signed-off-by: Edward Thomson <ethomson@edwardthomson.com> Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
60bd4b1c51
commit
4e55ed32db
11
read-cache.c
11
read-cache.c
@ -630,7 +630,7 @@ void set_object_name_for_intent_to_add_entry(struct cache_entry *ce)
|
||||
hashcpy(ce->sha1, sha1);
|
||||
}
|
||||
|
||||
int add_to_index(struct index_state *istate, const char *path, struct stat *st, int flags)
|
||||
int add_to_index(struct index_state *istate, const char *path, struct stat *st, int flags, int force_mode)
|
||||
{
|
||||
int size, namelen, was_same;
|
||||
mode_t st_mode = st->st_mode;
|
||||
@ -659,7 +659,9 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
|
||||
else
|
||||
ce->ce_flags |= CE_INTENT_TO_ADD;
|
||||
|
||||
if (trust_executable_bit && has_symlinks)
|
||||
if (S_ISREG(st_mode) && force_mode)
|
||||
ce->ce_mode = create_ce_mode(force_mode);
|
||||
else if (trust_executable_bit && has_symlinks)
|
||||
ce->ce_mode = create_ce_mode(st_mode);
|
||||
else {
|
||||
/* If there is an existing entry, pick the mode bits and type
|
||||
@ -720,12 +722,13 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int add_file_to_index(struct index_state *istate, const char *path, int flags)
|
||||
int add_file_to_index(struct index_state *istate, const char *path,
|
||||
int flags, int force_mode)
|
||||
{
|
||||
struct stat st;
|
||||
if (lstat(path, &st))
|
||||
die_errno("unable to stat '%s'", path);
|
||||
return add_to_index(istate, path, &st, flags);
|
||||
return add_to_index(istate, path, &st, flags, force_mode);
|
||||
}
|
||||
|
||||
struct cache_entry *make_cache_entry(unsigned int mode,
|
||||
|
||||
Reference in New Issue
Block a user