Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCM commit message #4877

Merged
merged 6 commits into from
Apr 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
jgsogo marked this conversation as resolved.
Show resolved Hide resolved
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