Skip to content

Commit

Permalink
Merge pull request #241 from tusharmakkar08/issue-143-improving-commi…
Browse files Browse the repository at this point in the history
…t-message

Issue 143 improving commit message
  • Loading branch information
vtemian authored Aug 11, 2016
2 parents 61087ac + 9b710d2 commit db2dab1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ to this project (in alphabetical order):
* Emanuel Danci <[email protected]>
* Vlad Temian <[email protected]>
* Justus Perlwitz <[email protected]>
* Tushar Makkar <[email protected]>

* Your name could stand here :)
17 changes: 13 additions & 4 deletions gitfs/worker/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,20 @@ def commit(self, jobs):
message = jobs[0]['params']['message']
else:
updates = set([])
number_of_removal = 0
number_of_additions = 0
for job in jobs:
updates = updates | set(job['params']['add'])
updates = updates | set(job['params']['remove'])

message = "Update {} items".format(len(updates))
removal_set = set(job['params']['remove'])
addition_set = set(job['params']['add'])
number_of_removal += len(removal_set)
number_of_additions += len(addition_set)
updates = updates | removal_set | addition_set
message = "Update {} items. ".format(len(updates))
if number_of_additions:
message += "Added {} items. ".format(number_of_additions)
if number_of_removal:
message += "Removed {} items. ".format(number_of_removal)
message = message.strip()

old_head = self.repository.head.target
new_commit = self.repository.commit(message, self.author,
Expand Down
12 changes: 6 additions & 6 deletions tests/integrations/current/test_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def test_delete_a_directory(self, gitfs_log):
shutil.rmtree("{}/a_directory/".format(self.current_path))

with pull(self.sh):
self.assert_commit_message("Update 2 items")
self.assert_commit_message("Update 2 items. Removed 2 items.")
self.assert_new_commit()

assert os.path.exists(path) is False
Expand Down Expand Up @@ -93,7 +93,7 @@ def test_link_a_file(self, gitfs_log):
os.link(filename, link_name)

with pull(self.sh):
self.assert_commit_message("Update 2 items")
self.assert_commit_message("Update 2 items. Added 2 items.")

is_link = os.path.isfile(link_name)
assert is_link is not False
Expand Down Expand Up @@ -158,7 +158,7 @@ def test_create_embedded_directory(self, gitfs_log):
assert os.path.exists(keep_file)

self.assert_new_commit()
commit_msg = "Update 2 items"
commit_msg = "Update 2 items. Added 2 items."
self.assert_commit_message(commit_msg)

def test_create_directory_inside_an_already_existing_directory(self, gitfs_log):
Expand Down Expand Up @@ -205,7 +205,7 @@ def test_create_embedded_directory_on_multiple_levels(self, gitfs_log):
assert os.path.exists(keep_file)

self.assert_new_commit()
commit_msg = "Update {} items".format(len(keep_files))
commit_msg = "Update {} items. Added {} items.".format(len(keep_files), len(keep_files))
self.assert_commit_message(commit_msg)

def test_create_embedded_directory_big_depth(self, gitfs_log):
Expand Down Expand Up @@ -283,7 +283,7 @@ def test_fsync(self, gitfs_log):

with pull(self.sh):
self.assert_new_commit()
self.assert_commit_message("Update 1 items")
self.assert_commit_message("Update 1 items. Added 2 items.")

def test_create(self, gitfs_log):
filename = "{}/new_empty_file".format(self.current_path)
Expand Down Expand Up @@ -357,7 +357,7 @@ def test_create_multiple_files(self, gitfs_log):
self.assert_new_commit()

with pull(self.sh):
self.assert_commit_message("Update {} items".format(no_of_files))
self.assert_commit_message("Update {} items. Added {} items.".format(no_of_files, no_of_files))

def test_delete_file(self, gitfs_log):
filename = "{}/deletable_file".format(self.current_path)
Expand Down
2 changes: 1 addition & 1 deletion tests/workers/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def test_commit_with_more_than_one_job(self):
repository=mocked_repo)
worker.commit(jobs)

asserted_message = "Update 2 items"
asserted_message = "Update 2 items. Added 2 items. Removed 1 items."
mocked_repo.commit.assert_called_once_with(asserted_message, author,
author)
assert mocked_repo.commits.update.call_count == 1
Expand Down

0 comments on commit db2dab1

Please sign in to comment.