With GNU cp, the -T option is used to ensure that the source directory will not be put inside the target directory. It will not cause to contents of the target directory to be removed.
The info documentation on this (info '(coreutils)Target directory') says (it's using mv as an example):
-T
--no-target-directory
Do not treat the last operand specially when it is a directory or a
symbolic link to a directory. This can help avoid race conditions
in programs that operate in a shared area. For example, when the
command mv /tmp/source /tmp/dest succeeds, there is no guarantee
that /tmp/source was renamed to /tmp/dest: it could have been
renamed to /tmp/dest/source instead, if some other process
created /tmp/dest as a directory. However, if mv -T /tmp/source /tmp/dest succeeds, there is no question that /tmp/source was
renamed to /tmp/dest.
Note that mv -T source dest will fail if dest is not empty.
To replace the contents of bar with that of foo in your example, use
rm -rf bar
cp -r foo bar
or,
rsync --archive --delete foo/ bar
cpfrom coreutils, or some other implementation of thecpcommand?treat DEST as a normal file. Normal files get overwritten when you copy over them. This is not the case here.