Skip to content

Commit

Permalink
Merge branch '212-moveToBaseDir'
Browse files Browse the repository at this point in the history
Build/Test Cases Summary
Enabled Packages:
Enabled all Packages
0) MPI_DEBUG => passed: passed=263,notpassed=0 (0.67 min)
1) SERIAL_RELEASE => passed: passed=263,notpassed=0 (0.61 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.56 min)
Other local commits for this build/test group: 86a4a1d, a7637e2, 1819f0f, a552da5, aa761ef, c7d9665
  • Loading branch information
bartlettroscoe committed Nov 3, 2017
2 parents edc4288 + 86a4a1d commit 98a1890
Show file tree
Hide file tree
Showing 4 changed files with 238 additions and 8 deletions.
163 changes: 158 additions & 5 deletions test/python_utils/gitdist_UnitTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ def __init__(self, useGit):
class test_createAsciiTable(unittest.TestCase):


def setUp(self):
self.gitdistMoveToBaseDir = os.environ.get("GITDIST_MOVE_TO_BASE_DIR", "")
os.environ["GITDIST_MOVE_TO_BASE_DIR"] = ""


def tearDown(self):
os.environ["GITDIST_MOVE_TO_BASE_DIR"] = self.gitdistMoveToBaseDir


def test_full_table(self):
tableData = [
{ "label" : "ID", "align" : "R",
Expand Down Expand Up @@ -197,6 +206,15 @@ def test_row_mismatch(self):
class test_gitdist_getRepoStats(unittest.TestCase):


def setUp(self):
self.gitdistMoveToBaseDir = os.environ.get("GITDIST_MOVE_TO_BASE_DIR", "")
os.environ["GITDIST_MOVE_TO_BASE_DIR"] = ""


def tearDown(self):
os.environ["GITDIST_MOVE_TO_BASE_DIR"] = self.gitdistMoveToBaseDir


def test_no_change(self):
try:
testDir = createAndMoveIntoTestDir("gitdist_getRepoStats_no_change")
Expand Down Expand Up @@ -562,7 +580,12 @@ class test_gitdist_getRepoVersionDictFromRepoVersionFileString(unittest.TestCase


def setUp(self):
None
self.gitdistMoveToBaseDir = os.environ.get("GITDIST_MOVE_TO_BASE_DIR", "")
os.environ["GITDIST_MOVE_TO_BASE_DIR"] = ""


def tearDown(self):
os.environ["GITDIST_MOVE_TO_BASE_DIR"] = self.gitdistMoveToBaseDir


def test_repoVersionFile_withSummary_1(self):
Expand Down Expand Up @@ -620,13 +643,20 @@ def assertContainsAllGitdistHelpSections(testObj, cmndOut):
GeneralScriptSupport.extractLinesMatchingRegex(cmndOut,"^USAGE TIPS:$"), "USAGE TIPS:\n")
testObj.assertEqual(
GeneralScriptSupport.extractLinesMatchingRegex(cmndOut,"^SCRIPT DEPENDENCIES:$"), "SCRIPT DEPENDENCIES:\n")
testObj.assertEqual(
GeneralScriptSupport.extractLinesMatchingRegex(cmndOut,"^MOVE TO BASE DIRECTORY:$"), "MOVE TO BASE DIRECTORY:\n")


class test_gitdist(unittest.TestCase):


def setUp(self):
None
self.gitdistMoveToBaseDir = os.environ.get("GITDIST_MOVE_TO_BASE_DIR", "")
os.environ["GITDIST_MOVE_TO_BASE_DIR"] = ""


def tearDown(self):
os.environ["GITDIST_MOVE_TO_BASE_DIR"] = self.gitdistMoveToBaseDir


def test_default(self):
Expand Down Expand Up @@ -673,18 +703,18 @@ def test_dist_help_all_help(self):
assertContainsAllGitdistHelpSections(self, cmndOut)


# Tet that --dist-help --help prints nice error message
# Test that --dist-help --help prints nice error message
def test_dist_help_help(self):
cmndOut = getCmndOutput(gitdistPath+" --dist-help --help")
cmndOut_expected = "gitdist: error: option --dist-help: invalid choice: '--help' (choose from '', 'overview', 'repo-selection-and-setup', 'dist-repo-status', 'repo-versions', 'aliases', 'usage-tips', 'script-dependencies', 'all')\n"
cmndOut_expected = "gitdist: error: option --dist-help: invalid choice: '--help' (choose from '', 'overview', 'repo-selection-and-setup', 'dist-repo-status', 'repo-versions', 'aliases', 'move-to-base-dir', 'usage-tips', 'script-dependencies', 'all')\n"
self.assertEqual(s(cmndOut), s(cmndOut_expected))


# Test --dist-helps=invalid-pick picked up as invalid value.
def test_dist_help_invalid_pick_help(self):
cmndOut = getCmndOutput(gitdistPath+" --dist-help=invalid-pick --help")
assertContainsGitdistHelpHeader(self, cmndOut)
errorToFind = "gitdist: error: option --dist-help: invalid choice: 'invalid-pick' (choose from '', 'overview', 'repo-selection-and-setup', 'dist-repo-status', 'repo-versions', 'aliases', 'usage-tips', 'script-dependencies', 'all')"
errorToFind = "gitdist: error: option --dist-help: invalid choice: 'invalid-pick' (choose from '', 'overview', 'repo-selection-and-setup', 'dist-repo-status', 'repo-versions', 'aliases', 'move-to-base-dir', 'usage-tips', 'script-dependencies', 'all')"
self.assertEqual(
GeneralScriptSupport.extractLinesMatchingSubstr(cmndOut,errorToFind), errorToFind+"\n")

Expand Down Expand Up @@ -1400,5 +1430,128 @@ def test_dist_repo_status_extra_args_fail(self):
os.chdir(testBaseDir)


def test_gitdist_move_to_base_dir_invalid_env_var(self):
os.environ["GITDIST_MOVE_TO_BASE_DIR"] = "INVALID"
cmndOut = getCmndOutput(gitdistPath+" status")
cmndOut_expected = "Error, env var GITDIST_MOVE_TO_BASE_DIR='INVALID' is invalid! Valid choices include empty '', IMMEDIATE_BASE, and EXTREME_BASE.\n"
print("cmndOut = ", cmndOut)
print("cmndOut_expected = ", cmndOut_expected)
self.assertEqual(s(cmndOut), s(cmndOut_expected))


def test_gitdist_move_to_base_dir(self):
os.chdir(testBaseDir)
try:

# Create a mock git meta-project.
testDir = createAndMoveIntoTestDir("gitdist_move_to_base_dir")
os.makedirs("ExtraRepo/path/to/somewhere")
open(".gitdist", "w").write(
".\n" \
"ExtraRepo\n"
)
open("ExtraRepo/.gitdist", "w").write(
".\n"
)
os.chdir("ExtraRepo/path/to/somewhere")

# Test with the default setting.
os.environ["GITDIST_MOVE_TO_BASE_DIR"] = ""
cmndOut = GeneralScriptSupport.getCmndOutput(gitdistPathMock+" status")
cmndOut_expected = \
"\n*** Base Git Repo: somewhere\n" \
"['mockgit', 'status']\n\n"
self.assertEqual(s(cmndOut), s(cmndOut_expected))

# Test moving up the directory tree until we find a .gitdist file.
os.environ["GITDIST_MOVE_TO_BASE_DIR"] = "IMMEDIATE_BASE"
cmndOut = GeneralScriptSupport.getCmndOutput(gitdistPathMock+" status")
cmndOut_expected = \
"\n*** Base Git Repo: ExtraRepo\n" \
"['mockgit', 'status']\n\n"
self.assertEqual(s(cmndOut), s(cmndOut_expected))

# Test moving up the directory tree until we find the outer-most .gitdist
# file.
os.environ["GITDIST_MOVE_TO_BASE_DIR"] = "EXTREME_BASE"
cmndOut = GeneralScriptSupport.getCmndOutput(gitdistPathMock+" status")
cmndOut_expected = \
"\n*** Base Git Repo: MockProjectDir\n" \
"['mockgit', 'status']\n\n" \
"*** Git Repo: ExtraRepo\n" \
"['mockgit', 'status']\n\n"
self.assertEqual(s(cmndOut), s(cmndOut_expected))

# Rename the .gitdist files .gitdist.default, and try the tests again.
os.rename("../../../.gitdist", "../../../.gitdist.default")
os.rename("../../../../.gitdist", "../../../../.gitdist.default")

# Test with the default setting.
os.environ["GITDIST_MOVE_TO_BASE_DIR"] = ""
cmndOut = GeneralScriptSupport.getCmndOutput(gitdistPathMock+" status")
cmndOut_expected = \
"\n*** Base Git Repo: somewhere\n" \
"['mockgit', 'status']\n\n"
self.assertEqual(s(cmndOut), s(cmndOut_expected))

# Test moving up the directory tree until we find a .gitdist file.
os.environ["GITDIST_MOVE_TO_BASE_DIR"] = "IMMEDIATE_BASE"
cmndOut = GeneralScriptSupport.getCmndOutput(gitdistPathMock+" status")
cmndOut_expected = \
"\n*** Base Git Repo: ExtraRepo\n" \
"['mockgit', 'status']\n\n"
self.assertEqual(s(cmndOut), s(cmndOut_expected))

# Test moving up the directory tree until we find the outer-most .gitdist
# file.
os.environ["GITDIST_MOVE_TO_BASE_DIR"] = "EXTREME_BASE"
cmndOut = GeneralScriptSupport.getCmndOutput(gitdistPathMock+" status")
cmndOut_expected = \
"\n*** Base Git Repo: MockProjectDir\n" \
"['mockgit', 'status']\n\n" \
"*** Git Repo: ExtraRepo\n" \
"['mockgit', 'status']\n\n"
self.assertEqual(s(cmndOut), s(cmndOut_expected))

finally:
os.chdir(testBaseDir)


def test_gitdist_move_to_base_dir_no_dist_gitdist_file(self):
os.chdir(testBaseDir)
try:

# Create a mock git meta-project but with no .gitdist[.default] files!
testDir = createAndMoveIntoTestDir("gitdist_move_to_base_dir_no_dist_gitdist_file")
os.makedirs(".git")
os.makedirs("ExtraRepo/.git")
os.makedirs("ExtraRepo/path/to/somewhere")
os.chdir("ExtraRepo/path/to/somewhere")

os.environ["GITDIST_MOVE_TO_BASE_DIR"] = ""
cmndOut = GeneralScriptSupport.getCmndOutput(gitdistPathMock+" status")
cmndOut_expected = \
"\n*** Base Git Repo: somewhere\n" \
"['mockgit', 'status']\n\n"
self.assertEqual(s(cmndOut), s(cmndOut_expected))

os.environ["GITDIST_MOVE_TO_BASE_DIR"] = "IMMEDIATE_BASE"
cmndOut = GeneralScriptSupport.getCmndOutput(gitdistPathMock+" status")
cmndOut_expected = \
"\n*** Base Git Repo: somewhere\n" \
"['mockgit', 'status']\n\n"
self.assertEqual(s(cmndOut), s(cmndOut_expected))

os.environ["GITDIST_MOVE_TO_BASE_DIR"] = "EXTREME_BASE"
cmndOut = GeneralScriptSupport.getCmndOutput(gitdistPathMock+" status")
cmndOut_expected = \
"\n*** Base Git Repo: somewhere\n" \
"['mockgit', 'status']\n\n"
self.assertEqual(s(cmndOut), s(cmndOut_expected))

finally:
os.chdir(testBaseDir)


if __name__ == '__main__':
unittest.main()
7 changes: 7 additions & 0 deletions tribits/doc/developers_guide/TribitsDevelopersGuide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8631,6 +8631,7 @@ from `gitdist --help`_ and ``gitdist --dist-help=<topic>``:
* `gitdist --dist-help=dist-repo-status`_
* `gitdist --dist-help=repo-versions`_
* `gitdist --dist-help=aliases`_
* `gitdist --dist-help=move-to-base-dir`_
* `gitdist --dist-help=usage-tips`_
* `gitdist --dist-help=script-dependencies`_
* `gitdist --dist-help=all`_
Expand Down Expand Up @@ -8675,6 +8676,12 @@ gitdist --dist-help=aliases
.. include:: gitdist-dist-help-aliases.txt
:literal:

gitdist --dist-help=move-to-base-dir
++++++++++++++++++++++++++++++++++++

.. include:: gitdist-dist-help-move-to-base-dir.txt
:literal:

gitdist --dist-help=usage-tips
++++++++++++++++++++++++++++++

Expand Down
1 change: 1 addition & 0 deletions tribits/doc/developers_guide/generate-dev-guide.sh
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ if [ "$TRIBITS_DEV_GUIDE_SKIP_OTHER_EXTRACTION" == "" ] ; then
generate_gitdist_dist_help_topic dist-repo-status
generate_gitdist_dist_help_topic repo-versions
generate_gitdist_dist_help_topic aliases
generate_gitdist_dist_help_topic move-to-base-dir
generate_gitdist_dist_help_topic usage-tips
generate_gitdist_dist_help_topic script-dependencies
generate_gitdist_dist_help_topic all
Expand Down
75 changes: 72 additions & 3 deletions tribits/python_utils/gitdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ def s(x):
'dist-repo-status',
'repo-versions',
'aliases',
'move-to-base-dir',
'usage-tips',
'script-dependencies'
'script-dependencies',
]


Expand Down Expand Up @@ -468,6 +469,69 @@ def getHelpTopicsStr():
helpTopicsDict.update( { 'aliases' : usefulAliasesHelp } )


moveToBaseDirHelp = r"""
MOVE TO BASE DIRECTORY:
By default, when you run gitdist, it will look in your current working
directory for a .gitdist[.default] file. If it fails to find one, it will
treat the current directory as the base git repository (as if there was a
.gitdist file in it, having a single line with only "." in it) and then run as
usual. You have the ability to change this behavior by setting the
GITDIST_MOVE_TO_BASE_DIR environment variable.
To describe the behavior for the differ net options, consider the following set
of nested git repositories and directories:
BaseRepo/
.git
.gitdist
...
ExtraRepo/
.git
.gitdist
...
path/
...
to/
...
some/
...
directory/
...
The valid settings for GITDIST_MOVE_TO_BASE_DIR include:
"" (Empty)
This gives the default behavior where gitdist runs in the current working
directory.
IMMEDIATE_BASE
In this case, gitdist will start moving up the directory tree until it
finds a .gitdist[.default] file, and then run in the directory where it
finds it. In the above example, if you are in
BaseRepo/ExtraRepo/path/to/some/directory/ when you run gitdist, it will
move up to ExtraRepo to execute the command you give it from there.
EXTREME_BASE:
In this case, gitdist will continue moving up the directory tree until it
finds the outer-most repository containing a .gitdist[.default] file, and
then run in that directory. Given the directory tree above, if you were
in BaseRepo/ExtraRepo/path/to/some/directory, it will move up to BaseRepo
to execute the command you give it.
With either of the settings above, when gitdist is finished running, it will
leave you in the same directory you were in when you executed command in the
first place. Additionally, if no .gitdist[.default] file can be found, gitdist
will execute the command you give it in your current working directory, as if
GITDIST_MOVE_TO_BASE_DIR hadn't been set.
"""
helpTopicsDict.update( { 'move-to-base-dir' : moveToBaseDirHelp } )


usageTipsHelp = r"""
USAGE TIPS:
Expand Down Expand Up @@ -1057,16 +1121,21 @@ def getCommandlineOps():
elif moveToBaseDir == "IMMEDIATE_BASE":
# Run gitdist in the immediate base dir where .gitdist[.default] exists
currentPath = os.getcwd()
foundIt = False
while 1:
if ((os.path.isfile(os.path.join(currentPath, ".gitdist"))) or
(os.path.isfile(os.path.join(currentPath, ".gitdist.default")))):
foundIt = True
break
currentPath, currentDir = os.path.split(currentPath)
os.chdir(currentPath)
if currentDir == "":
break
if foundIt:
os.chdir(currentPath)
else:
print(
"Error, env var GITDIST_MOVE_TO_BASE_DIR='"+moveToBaseDir+"' is invalid!"
+ " Valid choices include empty '', IMMEDIATE_BASE, and EXTREME_BASE")
+ " Valid choices include empty '', IMMEDIATE_BASE, and EXTREME_BASE.")
sys.exit(1)

#
Expand Down

0 comments on commit 98a1890

Please sign in to comment.