git-commitflow 1.0.9__tar.gz → 1.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: git-commitflow
3
- Version: 1.0.9
3
+ Version: 1.1.0
4
4
  Summary: A git add/commit/push helper
5
5
  Home-page: https://github.com/jamescherti/git-commitflow
6
6
  Author: James Cherti
@@ -39,9 +39,10 @@ Dynamic: summary
39
39
  The `git-commitflow` tool is an interactive command-line interface that assists with the Git operations.
40
40
 
41
41
  Running `git-commitflow` guides the user through the following interactive steps:
42
- - Prompting the user to add files (`git add`),
43
- - Displaying differences to ensure accuracy and prevent mistakes before committing (`git diff`),
44
- - Prompting the user to enter a commit message and then committing the changes (`git commit`),
42
+ - Prompting the user to add files (`git add`).
43
+ - Displaying differences to ensure accuracy and prevent mistakes before committing (`git diff`).
44
+ - Prompting the user to enter a commit message and then committing the changes (`git commit`).
45
+ - It first attempts to merge using `--ff-only`; if the merge fails, it prompts the user to confirm whether to proceed with a rebase using `--rebase` and `--autostash`. Afterward, it commits the changes.
45
46
  - Optional (`-p` flag): Pushing updates to the remote repository (`git push`). The references are only pushed when they have never been pushed before. The `git-commitflow` tool maintains a list of references that have been pushed, preventing multiple pushes of the same reference. This reduces unnecessary pushes.
46
47
 
47
48
  One significant benefit of the `git-commitflow` tool is that it enhances the user's awareness and control over their changes before committing. This reduces the likelihood of including unintended files or alterations in commits, promoting a cleaner and more organized version history.
@@ -6,9 +6,10 @@
6
6
  The `git-commitflow` tool is an interactive command-line interface that assists with the Git operations.
7
7
 
8
8
  Running `git-commitflow` guides the user through the following interactive steps:
9
- - Prompting the user to add files (`git add`),
10
- - Displaying differences to ensure accuracy and prevent mistakes before committing (`git diff`),
11
- - Prompting the user to enter a commit message and then committing the changes (`git commit`),
9
+ - Prompting the user to add files (`git add`).
10
+ - Displaying differences to ensure accuracy and prevent mistakes before committing (`git diff`).
11
+ - Prompting the user to enter a commit message and then committing the changes (`git commit`).
12
+ - It first attempts to merge using `--ff-only`; if the merge fails, it prompts the user to confirm whether to proceed with a rebase using `--rebase` and `--autostash`. Afterward, it commits the changes.
12
13
  - Optional (`-p` flag): Pushing updates to the remote repository (`git push`). The references are only pushed when they have never been pushed before. The `git-commitflow` tool maintains a list of references that have been pushed, preventing multiple pushes of the same reference. This reduces unnecessary pushes.
13
14
 
14
15
  One significant benefit of the `git-commitflow` tool is that it enhances the user's awareness and control over their changes before committing. This reduces the likelihood of including unintended files or alterations in commits, promoting a cleaner and more organized version history.
@@ -42,41 +42,38 @@ GIT_DIFF_OPTS: List[str] = []
42
42
  MIN_COMMIT_MESSAGE_SIZE = 1
43
43
  GIT_COMMITFLOW_DATA_DIR = Path("~/.config/git-commitflow").expanduser()
44
44
  CACHE_FILE = GIT_COMMITFLOW_DATA_DIR / "repo-data.json"
45
- IGNORE_FILENAMES_REGEX: List[str] = []
45
+ IGNORE_FILENAMES_REGEX: list = []
46
46
  HISTORY_LENGTH = 256
47
47
 
48
48
 
49
49
  class GitCommitFlow:
50
50
  def __init__(self):
51
- GIT_COMMITFLOW_DATA_DIR.mkdir(parents=True, exist_ok=True)
52
-
53
51
  self.args = self._parse_args()
52
+ GIT_COMMITFLOW_DATA_DIR.mkdir(parents=True, exist_ok=True)
54
53
 
55
- self.git_repo_dir = None
56
-
57
- self.git_repo_dir = None
58
- self.find_git_repo_dir() # Update self.git_repo_dir
59
-
60
- self.amount_commits = self.count_commits()
61
- self.cache = CacheFile(CACHE_FILE)
62
-
54
+ self.git_repo_dir = self._find_git_repo_dir()
63
55
  self.branch = self._get_first_line_cmd("git symbolic-ref --short HEAD")
56
+ self.amount_commits = self._count_commits()
57
+ self.readline_manager = self._init_prompt_and_history()
58
+ self.cache = CacheFile(CACHE_FILE)
64
59
 
60
+ def _init_prompt_and_history(self):
65
61
  # History
66
- self.prompt_history_file = None
67
-
68
- git_common_dir = \
62
+ prompt_history_file = None
63
+ dot_git_dir = \
69
64
  self._get_first_line_cmd("git rev-parse --git-common-dir").strip()
70
- if git_common_dir:
71
- self.prompt_history_file = \
72
- Path(git_common_dir).joinpath("git-commitflow-history.rl")
65
+ if not dot_git_dir:
66
+ print("Error: The .git directory could not be located",
67
+ file=sys.stderr)
68
+ sys.exit(1)
69
+
70
+ prompt_history_file = \
71
+ Path(dot_git_dir).joinpath("git-commitflow-history.rl")
73
72
 
74
- logging.debug(
75
- "[DEBUG] History file: %s", str(
76
- self.prompt_history_file))
77
- self.readline_manager = \
78
- ReadlineManager(history_file=self.prompt_history_file,
79
- history_length=HISTORY_LENGTH)
73
+ logging.debug("[DEBUG] History file: %s", str(prompt_history_file))
74
+
75
+ return ReadlineManager(history_file=prompt_history_file,
76
+ history_length=HISTORY_LENGTH)
80
77
 
81
78
  def _parse_args(self):
82
79
  """Parse command-line arguments."""
@@ -89,7 +86,11 @@ class GitCommitFlow:
89
86
  default=False,
90
87
  action="store_true",
91
88
  required=False,
92
- help="Git push after a successful commit",
89
+ help=("Git push after a successful commit. (The references are "
90
+ "pushed only if they have not been pushed previously. The "
91
+ "git-commitflow tool keeps track of the references that "
92
+ "have been pushed, preventing the same reference from being "
93
+ "pushed multiple times. This minimizes redundant pushes.)"),
93
94
  )
94
95
 
95
96
  parser.add_argument(
@@ -185,10 +186,6 @@ class GitCommitFlow:
185
186
  try:
186
187
  subprocess.check_call(["git", "commit"] + git_commit_opts)
187
188
 
188
- # TODO: maybe git show without a pager?
189
- # print()
190
- # subprocess.check_call(["git", "show"])
191
-
192
189
  print()
193
190
  print(Fore.GREEN + "[COMMIT] git commit was SUCCESSFUL." +
194
191
  Fore.RESET)
@@ -207,7 +204,10 @@ class GitCommitFlow:
207
204
  # Load cache
208
205
  # --------------
209
206
  remote_url = self._get_first_line_cmd("git ls-remote --get-url")
210
- branch = self.branch
207
+
208
+ # ------------------------
209
+ # Init commit refs (cache)
210
+ # ------------------------
211
211
  git_push_commit_refs = self.cache.get("git_push_commit_refs", {})
212
212
 
213
213
  try:
@@ -216,14 +216,14 @@ class GitCommitFlow:
216
216
  git_push_commit_refs[remote_url] = {}
217
217
 
218
218
  try:
219
- git_push_commit_refs[remote_url][branch]
219
+ git_push_commit_refs[remote_url][self.branch]
220
220
  except KeyError:
221
- git_push_commit_refs[remote_url][branch] = ""
221
+ git_push_commit_refs[remote_url][self.branch] = ""
222
222
 
223
223
  commit_ref = \
224
224
  self._get_first_line_cmd("git rev-parse --verify HEAD")
225
225
 
226
- if commit_ref == git_push_commit_refs[remote_url][branch]:
226
+ if commit_ref == git_push_commit_refs[remote_url][self.branch]:
227
227
  print(f"[PUSH] Already pushed: " f"{self.git_repo_dir}")
228
228
  return True
229
229
 
@@ -236,10 +236,12 @@ class GitCommitFlow:
236
236
  return True # No git remote
237
237
 
238
238
  try:
239
- # Show the remote branch that is tracked by the current local
239
+ # Display the remote branch that is tracked by the current local
240
240
  # branch The error message will be: fatal: no such branch: 'master'
241
241
  subprocess.check_call(["git", "rev-parse",
242
- "--symbolic-full-name", "HEAD@{u}"])
242
+ "--symbolic-full-name", "HEAD@{u}"],
243
+ stdout=subprocess.DEVNULL,
244
+ stderr=subprocess.DEVNULL)
243
245
 
244
246
  subprocess.check_call(["git", "fetch", "-a"])
245
247
  except subprocess.CalledProcessError as proc_err:
@@ -273,10 +275,9 @@ class GitCommitFlow:
273
275
  # Update cache file
274
276
  # ------------------
275
277
  if success:
276
- branch = self._get_first_line_cmd("git symbolic-ref --short HEAD")
277
278
  commit_ref = \
278
279
  self._get_first_line_cmd("git rev-parse --verify HEAD")
279
- git_push_commit_refs[remote_url][branch] = commit_ref
280
+ git_push_commit_refs[remote_url][self.branch] = commit_ref
280
281
  self.cache.set("git_push_commit_refs", git_push_commit_refs)
281
282
 
282
283
  return success
@@ -287,9 +288,9 @@ class GitCommitFlow:
287
288
  except subprocess.CalledProcessError:
288
289
  return default_value
289
290
 
290
- def find_git_repo_dir(self):
291
+ def _find_git_repo_dir(self):
291
292
  try:
292
- self.git_repo_dir = Path(
293
+ return Path(
293
294
  self._get_first_line_cmd("git rev-parse --show-toplevel",
294
295
  check=True)
295
296
  )
@@ -302,7 +303,7 @@ class GitCommitFlow:
302
303
  "is not a directory", file=sys.stderr)
303
304
  sys.exit(1)
304
305
 
305
- def count_commits(self):
306
+ def _count_commits(self):
306
307
  return len(self._run("git rev-list --all --count"))
307
308
 
308
309
  def _get_first_line_cmd(self, cmd, **kwargs) -> str:
@@ -388,8 +389,6 @@ class GitCommitFlow:
388
389
  # TODO: move this to a function
389
390
  logging.debug("[DEBUG] Previous message: %s", previous_message)
390
391
  logging.debug("[DEBUG] Commit message: %s", commit_message)
391
- # if self.prompt_history_file and not commit_message and previous_message:
392
- # self.readline_manager.append_to_history(previous_message)
393
392
 
394
393
  return commit_message
395
394
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: git-commitflow
3
- Version: 1.0.9
3
+ Version: 1.1.0
4
4
  Summary: A git add/commit/push helper
5
5
  Home-page: https://github.com/jamescherti/git-commitflow
6
6
  Author: James Cherti
@@ -39,9 +39,10 @@ Dynamic: summary
39
39
  The `git-commitflow` tool is an interactive command-line interface that assists with the Git operations.
40
40
 
41
41
  Running `git-commitflow` guides the user through the following interactive steps:
42
- - Prompting the user to add files (`git add`),
43
- - Displaying differences to ensure accuracy and prevent mistakes before committing (`git diff`),
44
- - Prompting the user to enter a commit message and then committing the changes (`git commit`),
42
+ - Prompting the user to add files (`git add`).
43
+ - Displaying differences to ensure accuracy and prevent mistakes before committing (`git diff`).
44
+ - Prompting the user to enter a commit message and then committing the changes (`git commit`).
45
+ - It first attempts to merge using `--ff-only`; if the merge fails, it prompts the user to confirm whether to proceed with a rebase using `--rebase` and `--autostash`. Afterward, it commits the changes.
45
46
  - Optional (`-p` flag): Pushing updates to the remote repository (`git push`). The references are only pushed when they have never been pushed before. The `git-commitflow` tool maintains a list of references that have been pushed, preventing multiple pushes of the same reference. This reduces unnecessary pushes.
46
47
 
47
48
  One significant benefit of the `git-commitflow` tool is that it enhances the user's awareness and control over their changes before committing. This reduces the likelihood of including unintended files or alterations in commits, promoting a cleaner and more organized version history.
@@ -23,7 +23,7 @@ from setuptools import find_packages, setup
23
23
 
24
24
  setup(
25
25
  name="git-commitflow",
26
- version="1.0.9",
26
+ version="1.1.0",
27
27
  packages=find_packages(),
28
28
  description="A git add/commit/push helper",
29
29
  long_description=((Path(__file__).parent.resolve().joinpath("README.md"))
File without changes
File without changes