Skip to content

Commit

Permalink
Merge pull request #20 from jacebrowning/fail-on-untracked
Browse files Browse the repository at this point in the history
Require --force with untracked files
  • Loading branch information
jacebrowning committed Mar 12, 2015
2 parents 2bf01ec + 0d649d9 commit 4d69266
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 53 deletions.
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ language: python
python:
- 3.3
- 3.4
before_install:
- sudo add-apt-repository ppa:git-core/ppa -y
- sudo apt-get update
install:
- sudo apt-get install git
- git --version
- pip install coveralls scrutinizer-ocular
before_script:
- make env
Expand Down
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Changelog
---------

- Automatically track dependencies that are on branches.
- Require '--force' when there are untracked files.

0.2 (2015/03/10)
----------------
Expand Down
19 changes: 14 additions & 5 deletions gdm/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def _call(self, *args,
visible=True, catch=True, ignore=False, capture=False):
if visible:
self._display_in(*args)
log.debug("running: %s", ' '.join(args))
return _call(*args, catch=catch, ignore=ignore, capture=capture)

def _display_in(self, *args):
Expand Down Expand Up @@ -88,14 +89,22 @@ def git_fetch(self, repo, rev=None):
def git_changes(self):
"""Determine if there are changes in the working tree."""
try:
kwargs = {'visible': False, 'catch': False}
self._git('update-index', '-q', '--refresh', **kwargs)
self._git('diff-files', '--quiet', **kwargs)
self._git('diff-index', '--cached', '--quiet', 'HEAD', **kwargs)
# refresh changes
self._git('update-index', '-q', '--refresh',
visible=False, catch=False)
# check for uncommitted changes
self._git('diff-index', '--quiet', 'HEAD',
visible=False, catch=False)
# check for untracked files
output = self._git('ls-files', '--others', '--exclude-standard',
visible=False, catch=False, capture=True)
except common.CallException:
return True
else:
return False
filenames = output.splitlines()
for filename in filenames:
log.debug("new file: %s", filename)
return bool(filenames)

def git_update(self, rev):
"""Update the working tree to the specified revision."""
Expand Down
6 changes: 2 additions & 4 deletions gdm/test/files/gdm.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
location: /tmp/gdm-test-dependencies
sources:
- repo: https://github.com/jacebrowning/gdm
- repo: https://github.com/jacebrowning/gdm-demo
dir: gdm_1
rev: example-branch
link: src/gdm_a
- repo: https://github.com/jacebrowning/gdm
- repo: https://github.com/jacebrowning/gdm-demo
dir: gdm_2
rev: example-tag
link: src/gdm_b
26 changes: 10 additions & 16 deletions gdm/test/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,17 @@
@pytest.mark.integration
def test_install():
"""Verify dependencies can be installed."""
try:

config = Config(FILES)
shutil.rmtree(config.location, ignore_errors=True)
assert not os.path.exists(config.location)

# clean install
assert gdm.install(FILES)
assert os.path.isdir(config.location)
# second install
assert gdm.install(FILES)
assert 'gdm_1' in os.listdir(config.location)
assert 'gdm_2' in os.listdir(config.location)

finally:
config = Config(FILES)
shutil.rmtree(config.location, ignore_errors=True)
assert not os.path.exists(config.location)

shutil.rmtree(os.path.join(FILES, 'src'), ignore_errors=True)
# clean install
assert gdm.install(FILES)
assert os.path.isdir(config.location)
# second install
assert gdm.install(FILES)
assert 'gdm_1' in os.listdir(config.location)
assert 'gdm_2' in os.listdir(config.location)


@pytest.mark.integration
Expand Down
40 changes: 17 additions & 23 deletions gdm/test/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# pylint: disable=R0201

import os
import shutil

import pytest

Expand Down Expand Up @@ -95,28 +94,23 @@ class TestInstallAndGet:

def test_multiple(self):
"""Verify the correct dependencies are installed."""
try:

count = install_deps(FILES)
assert 6 == count

deps = list(get_deps(FILES))
assert 6 == len(deps)
assert 'https://github.com/jacebrowning/gdm' == deps[0][1]
assert '972f095130da2c2796ae022b9b3f68925c19c4ed' == deps[0][2]
assert 'https://github.com/jacebrowning/gdm' == deps[1][1]
assert '19721d728ad84b7314b9d21156ca95f6b916cee7' == deps[1][2]
assert 'https://github.com/jacebrowning/gdm' == deps[2][1]
assert 'fb693447579235391a45ca170959b5583c5042d8' == deps[2][2]
assert 'https://github.com/jacebrowning/gdm' == deps[3][1]
# master branch always changes -------------------- deps[3][2]
assert 'https://github.com/jacebrowning/gdm' == deps[4][1]
# master branch always changes --------------------- deps[4][2]
assert 'https://github.com/jacebrowning/gdm' == deps[5][1]
assert '7bd138fe7359561a8c2ff9d195dff238794ccc04' == deps[5][2]

finally:
shutil.rmtree(os.path.join(FILES, 'src'), ignore_errors=True)
count = install_deps(FILES)
assert 6 == count

deps = list(get_deps(FILES))
assert 6 == len(deps)
assert 'https://github.com/jacebrowning/gdm-demo' == deps[0][1]
assert 'eb37743011a398b208dd9f9ef79a408c0fc10d48' == deps[0][2]
assert 'https://github.com/jacebrowning/gdm-demo' == deps[1][1]
assert 'ddbe17ef173538d1fda29bd99a14bab3c5d86e78' == deps[1][2]
assert 'https://github.com/jacebrowning/gdm-demo' == deps[2][1]
assert 'fb693447579235391a45ca170959b5583c5042d8' == deps[2][2]
assert 'https://github.com/jacebrowning/gdm-demo' == deps[3][1]
# master branch always changes --------------------- deps[3][2]
assert 'https://github.com/jacebrowning/gdm-demo' == deps[4][1]
# master branch always changes --------------------- deps[4][2]
assert 'https://github.com/jacebrowning/gdm-demo' == deps[5][1]
assert '7bd138fe7359561a8c2ff9d195dff238794ccc04' == deps[5][2]

def test_empty(self, tmpdir):
"""Verify zero dependencies are installed with no configuration."""
Expand Down
20 changes: 15 additions & 5 deletions gdm/test/test_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,26 @@ def test_fetch_rev_sha(self, mock_call):

def test_changes(self, mock_call):
"""Verify the commands to check for uncommitted changes."""
assert False is self.shell.git_changes()
self.shell.git_changes()
self.assert_calls(mock_call, [
# based on: http://stackoverflow.com/questions/3878624
"git update-index -q --refresh",
"git diff-files --quiet",
"git diff-index --cached --quiet HEAD",
"git diff-index --quiet HEAD",
"git ls-files --others --exclude-standard",
])

def test_changes_true(self, _):
"""Verify the commands to check for uncommitted changes (w/ changes)."""
def test_changes_false(self, _):
"""Verify the absence of changes can be detected."""
with patch('gdm.shell._call', Mock(return_value="")):
assert False is self.shell.git_changes()

def test_changes_true_untracked(self, _):
"""Verify untracked files can be detected."""
with patch('gdm.shell._call', Mock(return_value="file_1")):
assert True is self.shell.git_changes()

def test_changes_true_uncommitted(self, _):
"""Verify uncommitted changes can be detected."""
with patch('gdm.shell._call', Mock(side_effect=CallException)):
assert True is self.shell.git_changes()

Expand Down

0 comments on commit 4d69266

Please sign in to comment.