Skip to content

Commit

Permalink
SCM commit message (#4877)
Browse files Browse the repository at this point in the history
* SCM commit message

- Retrieve last commit message (Git and SVN)

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* Ignore git log error

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* Retrieve SVN subrepo commit message

Co-Authored-By: uilianries <uilianries@gmail.com>

* Commit message must be exactly as expected

Co-Authored-By: uilianries <uilianries@gmail.com>

* #4877 Move git and svn tests

- SCM tests were moved to a new place, so both message tests need
  to be reallocated to there.
  • Loading branch information
uilianries authored and lasote committed Apr 29, 2019
1 parent 7271fc8 commit 27d3860
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
12 changes: 12 additions & 0 deletions conans/client/tools/scm.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,14 @@ def get_commit(self):

get_revision = get_commit

def get_commit_message(self):
self.check_repo()
try:
message = self.run("log -1 --format=%s%n%b")
return message.strip()
except Exception:
return None

def is_pristine(self):
self.check_repo()
status = self.run("status --porcelain").strip()
Expand Down Expand Up @@ -353,6 +361,10 @@ def is_pristine(self):
def get_revision(self):
return self._show_item('revision')

def get_revision_message(self):
output = self.run("log -r COMMITTED").splitlines()
return output[3] if len(output) > 2 else None

def get_repo_root(self):
return self._show_item('wc-root')

Expand Down
15 changes: 15 additions & 0 deletions conans/test/unittests/client/tools/scm/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,21 @@ def build(self):
client.run("create . user/channel", assert_error=True)
self.assertIn("specify a branch to checkout", client.out)

def git_commit_message_test(self):
client = TestClient()
git_repo = temp_folder()
client.runner("git init .", cwd=git_repo)
client.runner('git config user.email "you@example.com"', cwd=git_repo)
client.runner('git config user.name "Your Name"', cwd=git_repo)
client.runner("git checkout -b dev", cwd=git_repo)
git = Git(git_repo)
self.assertIsNone(git.get_commit_message())
save(os.path.join(git_repo, "test"), "contents")
client.runner("git add test", cwd=git_repo)
client.runner('git commit -m "first commit"', cwd=git_repo)
self.assertEqual("dev", git.get_branch())
self.assertEqual("first commit", git.get_commit_message())


class GitToolsTests(unittest.TestCase):

Expand Down
15 changes: 15 additions & 0 deletions conans/test/unittests/client/tools/scm/test_svn.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ def test_clone(self):
svn.checkout(url=project_url)
self.assertTrue(os.path.exists(os.path.join(tmp_folder, 'myfile')))

def svn_revision_message_test(self):
tmp_folder = self.gimme_tmp()
svn = SVN(folder=tmp_folder)
svn.checkout(url=self.repo_url)
self.assertIsNone(svn.get_revision_message())

new_file = os.path.join(tmp_folder, "new_file")
with open(new_file, "w") as f:
f.write("content")

svn.run('add new_file')
svn.run('commit -m "add to file"')
svn.run('update')
self.assertEqual("add to file", svn.get_revision_message())

def test_revision_number(self):
svn = SVN(folder=self.gimme_tmp())
svn.checkout(url=self.repo_url)
Expand Down
1 change: 0 additions & 1 deletion conans/test/unittests/util/tools_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,6 @@ def build(self):
client.save({"conanfile.py": conanfile, "file.txt": "hello\r\n"})
client.run("create . user/channel")


class CollectLibTestCase(unittest.TestCase):

def collect_libs_test(self):
Expand Down

0 comments on commit 27d3860

Please sign in to comment.