diff options
author | Alexander Potashev <aspotashev@gmail.com> | 2009-01-11 15:19:12 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2009-01-11 13:26:29 -0800 |
commit | 55892d23981917aefdb387ad7d0429f90cbd446a (patch) | |
tree | 72b1aab773fa37b50d07991de8a227994f1d6a7b /dir.c | |
parent | add is_dot_or_dotdot inline function (diff) | |
download | tgif-55892d23981917aefdb387ad7d0429f90cbd446a.tar.xz |
Allow cloning to an existing empty directory
The die() message updated accordingly.
The previous behaviour was to only allow cloning when the destination
directory doesn't exist.
[jc: added trivial tests]
Signed-off-by: Alexander Potashev <aspotashev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'dir.c')
-rw-r--r-- | dir.c | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -777,6 +777,25 @@ int is_inside_dir(const char *dir) return get_relative_cwd(buffer, sizeof(buffer), dir) != NULL; } +int is_empty_dir(const char *path) +{ + DIR *dir = opendir(path); + struct dirent *e; + int ret = 1; + + if (!dir) + return 0; + + while ((e = readdir(dir)) != NULL) + if (!is_dot_or_dotdot(e->d_name)) { + ret = 0; + break; + } + + closedir(dir); + return ret; +} + int remove_dir_recursively(struct strbuf *path, int only_empty) { DIR *dir = opendir(path->buf); |