Skip to content

Commit

Permalink
Make clean of ignored files from orig-dir off by default (TriBITSPub#242
Browse files Browse the repository at this point in the history
)

After some more thought, I realized that turning on the cleaning of ignored
files from the orig-dir by default was just a bit too dangerous.  I would
rather that too much get synced by accident by people who are just starting to
use this script than to have the script delete a bunch of files and
directroies from the orig-dir that the user was depending on and will get very
angry if those files got deleted.

I updated the automated tests to run with both cases and updated the
documentation for the new default behavior.

Build/Test Cases Summary
Enabled Packages:
Enabled all Packages
0) MPI_DEBUG => passed: passed=263,notpassed=0 (0.79 min)
1) SERIAL_RELEASE => passed: passed=263,notpassed=0 (0.59 min)
2) MPI_DEBUG_CMAKE-3.6.2 => passed: passed=284,notpassed=0 (0.63 min)
3) SERIAL_RELEASE_CMAKE-3.6.2 => passed: passed=284,notpassed=0 (0.51 min)
  • Loading branch information
bartlettroscoe committed Nov 17, 2017
1 parent 9c8b47e commit 957d04a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 24 deletions.
25 changes: 23 additions & 2 deletions test/python_utils/SnapshotDir_UnitTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,13 @@ def test_override_orig_dest_dirs(self):
)


def test_full_snapshot(self):
def test_snapshot_default(self):
runSnapshotDirTestCase(
self,
["--orig-dir=dummy/orig-dir/", "--dest-dir=dummy/dest-dir/"],
[
g_gitDiffHead,
g_gitDiffHead,
g_gitClean,
g_gitRevParse,
g_gitRemote,
g_gitLog,
Expand All @@ -189,6 +188,28 @@ def test_full_snapshot(self):
]
)

def test_snapshot_clean_ignored(self):
runSnapshotDirTestCase(
self,
["--orig-dir=dummy/orig-dir/", "--dest-dir=dummy/dest-dir/",
"--clean-ignored-files-orig-dir"],
[
g_gitDiffHead,
g_gitDiffHead,
g_gitClean,
g_gitRevParse,
g_gitRemote,
g_gitLog,
g_rsync,
g_gitLogSha1,
g_gitAdd,
g_gitCommit,
],
[
"git clean -xdf"
]
)

# ToDo: Test assert failure of clean origDir ...

# ToDo: Test skipping test of clean origDir ...
Expand Down
45 changes: 23 additions & 22 deletions tribits/python_utils/SnapshotDir.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,16 @@ def getDefaultDestDir(self):
By default, this script does the following:
1) Asserts that the git repo for 'orig-dir' is clean (i.e. no uncommitted
files, no unknown files, etc.). This can be disabled by passing in
--allow-dirty-orig-dir.
1) Assert that the git repo for 'orig-dir' is clean (i.e. no uncommitted
files, no unknown files, etc.). (Can be disabled by passing in
--allow-dirty-orig-dir.)
2) Asserts that the git repo for <some-dest-dir>/ is clean (see above). This
can be disabled by passing in --allow-dirty-dest-dir.
2) Assert that the git repo for <some-dest-dir>/ is clean (see above). (Can
be disabled by passing in --allow-dirty-dest-dir.)
3) Cleans out the ignored files from <some-source-dir>/orig-dir using 'git
clean -xdf' run in that directory. This can be disabled by passing in
--no-clean-orig-ingored-files.
3) Clean out the ignored files from <some-source-dir>/orig-dir using 'git
clean -xdf' run in that directory. (Only if --clean-ignored-files-orig-dir
is specified.)
4) Run 'rsync -cav --delete' to copy the contents from 'orig-dir' to
'dest-dir', excluding the '.git/' directory if it exists in either git repo
Expand Down Expand Up @@ -171,20 +171,21 @@ def getDefaultDestDir(self):
.git/ directory when syncing.
* The cleaning of the orig-dir/ using 'git clean -xdf' may be somewhat
dangerous but it is done by default to avoid copying locally-ignored files
in orig-dir/ (e.g. ignored in .git/info/excludes but not in a committed
.gitignore file) that get copied to and then committed into the dest-dir/
repoo. Therefore, be sure you don't have any ignored files in orig-dir/
that you want to keep before you run this script!
dangerous but it is recommended that it be preformed by passing in
--clean-ignored-files-orig-dir to avoid copying locally-ignored files in
orig-dir/ (e.g. ignored in .git/info/excludes but not in a committed
.gitignore file) that get copied to and then committed in the dest-dir/
repo. Therefore, be sure you don't have any ignored files in orig-dir/ that
you want to keep before you run this script!
* Snapshotting with this script will create an exact duplicate of 'orig-dir'
in 'dest-dir' and therefore if there are any local changes to the files or
chagnes after the last snapshot, they will get wiped out. To avoid this, do
the snapshot on a branch in the 'dest-dir' git repo, then merge that branch
into the master branch in 'dest-dir' repo that has the local changes. As
long as there are no merge conflicts, this will preserve local changes for
the mirrored directories and files. This strategy works very well in many
cases.
changes after the last snapshot, they will get wiped out. To avoid this,
one can the snapshot on a branch in the 'dest-dir' git repo, then merge that
branch into the main branch (e.g. 'master') in 'dest-dir' repo. As long as
there are no merge conflicts, this will preserve local changes for the
mirrored directories and files. This strategy can work well as a way to
allow for local modifications but still do the snapshotting..
"""


Expand Down Expand Up @@ -257,11 +258,11 @@ def snapshotDirMainDriver(cmndLineArgs, defaultOptionsIn = None, stdout = None):

clp.add_option(
"--clean-ignored-files-orig-dir", dest="cleanIgnoredFilesOrigDir", action="store_true",
help="Clean out the ignored files from orig-dir/ before snapshotting. [default]" )
help="Clean out the ignored files from orig-dir/ before snapshotting." )
clp.add_option(
"--no-clean-ignored-files-orig-dir", dest="cleanIgnoredFilesOrigDir", action="store_false",
default=True,
help="Do not clean out orig-dir/ ignored files before snapshotting." )
default=False,
help="Do not clean out orig-dir/ ignored files before snapshotting. [default]" )

clp.add_option(
"--do-rsync", dest="doRsync", action="store_true",
Expand Down

0 comments on commit 957d04a

Please sign in to comment.