skilleter-thingy 0.1.22__py3-none-any.whl → 0.1.23__py3-none-any.whl

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.

Potentially problematic release.


This version of skilleter-thingy might be problematic. Click here for more details.

@@ -109,6 +109,28 @@ def git_run_status(cmd, stdout=None, stderr=None, path=None, redirect=True):
109
109
 
110
110
  ################################################################################
111
111
 
112
+ def git_dir(path=None):
113
+ """ Return the relative path to the .git directory """
114
+
115
+ if not path:
116
+ path = os.getcwd()
117
+
118
+ return pygit2.discover_repository(path)
119
+
120
+ ################################################################################
121
+
122
+ def working_tree(path=None):
123
+ """ Location of the current working tree or None if we are not in a working tree """
124
+
125
+ repo_dir = git_dir(path=path)
126
+
127
+ if repo_dir:
128
+ return os.path.abspath(os.path.join(repo_dir, os.pardir))
129
+
130
+ return None
131
+
132
+ ################################################################################
133
+
112
134
  def clone(reponame, path=None):
113
135
  """ Clone a repo """
114
136
 
@@ -121,7 +143,7 @@ def clone(reponame, path=None):
121
143
 
122
144
  ################################################################################
123
145
 
124
- def init(reponame, bare=False):
146
+ def init(reponame, bare=False, path=None):
125
147
  """ Initialise a new working tree """
126
148
 
127
149
  cmd = ['init']
@@ -131,11 +153,11 @@ def init(reponame, bare=False):
131
153
 
132
154
  cmd.append(reponame)
133
155
 
134
- return git(cmd)
156
+ return git(cmd, path=path)
135
157
 
136
158
  ################################################################################
137
159
 
138
- def iscommit(commit, remote=False, remote_only=False):
160
+ def iscommit(commit, remote=False, remote_only=False, path=None):
139
161
  """ Return True if "commit" is a valid SHA1, branch or tag
140
162
  If remote==True then if there are no direct matches it will also
141
163
  check for a matching remote branch
@@ -146,7 +168,7 @@ def iscommit(commit, remote=False, remote_only=False):
146
168
  if not remote_only:
147
169
  cmd = ['cat-file', '-t', commit]
148
170
  try:
149
- result = git(cmd)[0]
171
+ result = git(cmd, path=path)[0]
150
172
 
151
173
  return result in ('commit', 'tag')
152
174
  except GitError:
@@ -155,7 +177,7 @@ def iscommit(commit, remote=False, remote_only=False):
155
177
  # Optionally look for matching remote branch
156
178
 
157
179
  if remote or remote_only:
158
- for branch in branches(all=True):
180
+ for branch in branches(all=True, path=path):
159
181
  if branch.startswith('remotes/'):
160
182
  localbranch = '/'.join(branch.split('/')[2:])
161
183
 
@@ -176,44 +198,44 @@ def branch(branchname='HEAD', path=None):
176
198
 
177
199
  ################################################################################
178
200
 
179
- def tag():
201
+ def tag(path=None):
180
202
  """ If the current commit is tagged, return the tag(s) or None """
181
203
 
182
204
  try:
183
- return git(['describe', '--tags', '--exact-match'])[0]
205
+ return git(['describe', '--tags', '--exact-match'], path=path)[0]
184
206
  except GitError:
185
207
  return None
186
208
 
187
209
  ################################################################################
188
210
 
189
- def tags():
211
+ def tags(path=None):
190
212
  """ Return the list of tags in the current repo """
191
213
 
192
- return git(['tag', '--list'])
214
+ return git(['tag', '--list'], path=path)
193
215
 
194
216
  ################################################################################
195
217
 
196
- def tag_delete(tag, push=False):
218
+ def tag_delete(tag, push=False, path=None):
197
219
  """Delete a tag, optionally pushing the deletion"""
198
220
 
199
- git(['tag', '-d', tag])
221
+ git(['tag', '-d', tag], path=path)
200
222
 
201
223
  if push:
202
- git(['push', '--delete', tag])
224
+ git(['push', 'origin', '--delete', tag], path=path)
203
225
 
204
226
  ################################################################################
205
227
 
206
- def tag_apply(tag, push=False):
228
+ def tag_apply(tag, push=False, path=None):
207
229
  """Apply a tag, optionally pushing it"""
208
230
 
209
- git(['tag', tag])
231
+ git(['tag', tag], path=path)
210
232
 
211
233
  if push:
212
- git(['push', tag])
234
+ git(['push', 'origin', tag], path=path)
213
235
 
214
236
  ################################################################################
215
237
 
216
- def current_commit(short=False):
238
+ def current_commit(short=False, path=None):
217
239
  """ Return the SHA1 of the current commit """
218
240
 
219
241
  cmd = ['rev-parse']
@@ -223,7 +245,7 @@ def current_commit(short=False):
223
245
 
224
246
  cmd.append('HEAD')
225
247
 
226
- return git(cmd)[0]
248
+ return git(cmd, path=path)[0]
227
249
 
228
250
  ################################################################################
229
251
 
@@ -256,23 +278,23 @@ def checkout(branch, create=False, path=None):
256
278
 
257
279
  ################################################################################
258
280
 
259
- def merge(branch):
281
+ def merge(branch, path=None):
260
282
  """ Merge a branch """
261
283
 
262
284
  cmd = ['merge', branch]
263
285
 
264
- return git(cmd)
286
+ return git(cmd, path=path)
265
287
 
266
288
  ################################################################################
267
289
 
268
- def abort_merge():
290
+ def abort_merge(path=None):
269
291
  """ Abort the current merge """
270
292
 
271
- return git(['merge', '--abort'])
293
+ return git(['merge', '--abort'], path=path)
272
294
 
273
295
  ################################################################################
274
296
 
275
- def set_upstream(branch, upstream=None):
297
+ def set_upstream(branch, upstream=None, path=None):
276
298
  """ Set the default upstream branch """
277
299
 
278
300
  if not upstream:
@@ -280,7 +302,7 @@ def set_upstream(branch, upstream=None):
280
302
 
281
303
  cmd = ['branch', f'--set-upstream-to={upstream}', branch]
282
304
 
283
- return git(cmd)
305
+ return git(cmd, path=path)
284
306
 
285
307
  ################################################################################
286
308
 
@@ -296,7 +318,7 @@ def fetch(all=False, path=None):
296
318
 
297
319
  ################################################################################
298
320
 
299
- def rebase_required(branch, parent):
321
+ def rebase_required(branch, parent, path=None):
300
322
  """ Return True if the specified branch needs to be rebased against its
301
323
  parent.
302
324
  """
@@ -304,8 +326,8 @@ def rebase_required(branch, parent):
304
326
  # Find the latest commit on the parent branch and the most recent commit
305
327
  # that both branches have in common.
306
328
 
307
- parent_tip = git(['show-ref', '--heads', '-s', parent])
308
- common_commit = git(['merge-base', parent, branch])
329
+ parent_tip = git(['show-ref', '--heads', '-s', parent], path=path)
330
+ common_commit = git(['merge-base', parent, branch], path=path)
309
331
 
310
332
  # Different commits, so rebase is required
311
333
 
@@ -320,36 +342,36 @@ def rebase(branch, path=None):
320
342
 
321
343
  ################################################################################
322
344
 
323
- def abort_rebase():
345
+ def abort_rebase(path=None):
324
346
  """ Abort the current rebase """
325
347
 
326
- return git(['rebase', '--abort'])
348
+ return git(['rebase', '--abort'], path=path)
327
349
 
328
350
  ################################################################################
329
351
 
330
- def rebasing():
352
+ def rebasing(path=None):
331
353
  """ Return True if currently rebasing, False otherwise """
332
354
 
333
- gitdir = git_dir()
355
+ gitdir = git_dir(path=path)
334
356
 
335
357
  return os.path.isdir(os.path.join(gitdir, 'rebase-apply')) or \
336
358
  os.path.isdir(os.path.join(gitdir, 'rebase-merge'))
337
359
 
338
360
  ################################################################################
339
361
 
340
- def bisecting():
362
+ def bisecting(path=None):
341
363
  """ Return True if currently rebasing, False otherwise """
342
364
 
343
- gitdir = git_dir()
365
+ gitdir = git_dir(path=path)
344
366
 
345
367
  return os.path.isfile(os.path.join(gitdir, 'BISECT_START'))
346
368
 
347
369
  ################################################################################
348
370
 
349
- def merging():
371
+ def merging(path=None):
350
372
  """ Return True if currently merging, False otherwise """
351
373
 
352
- gitdir = git_dir()
374
+ gitdir = git_dir(path=path)
353
375
 
354
376
  return os.path.isfile(os.path.join(gitdir, 'MERGE_MODE'))
355
377
 
@@ -358,7 +380,7 @@ def merging():
358
380
  def remotes(path=None):
359
381
  """ Return the list of git remotes """
360
382
 
361
- repo = pygit2.Repository(path or os.getcwd())
383
+ repo = pygit2.Repository(git_dir(path=path))
362
384
 
363
385
  git_remotes = {}
364
386
 
@@ -369,10 +391,10 @@ def remotes(path=None):
369
391
 
370
392
  ################################################################################
371
393
 
372
- def remote_names():
394
+ def remote_names(path=None):
373
395
  """ Return the list of remote names """
374
396
 
375
- repo = pygit2.Repository(os.getcwd())
397
+ repo = pygit2.Repository(git_dir(path=path))
376
398
 
377
399
  results = list(repo.remotes.names())
378
400
 
@@ -380,10 +402,10 @@ def remote_names():
380
402
 
381
403
  ################################################################################
382
404
 
383
- def project(short=False):
405
+ def project(short=False, path=None):
384
406
  """ Return the name of the current git project """
385
407
 
386
- git_remotes = remotes()
408
+ git_remotes = remotes(path=path)
387
409
  name = ''
388
410
 
389
411
  for remote in git_remotes:
@@ -409,7 +431,7 @@ def project(short=False):
409
431
 
410
432
  ################################################################################
411
433
 
412
- def status_info(ignored=False, untracked=False):
434
+ def status_info(ignored=False, untracked=False, path=None):
413
435
  """ Git status, optionally include files ignored in .gitignore and/or
414
436
  untracked files.
415
437
  Returns data in the same dictionary format as used by commit_info() """
@@ -422,7 +444,7 @@ def status_info(ignored=False, untracked=False):
422
444
  if untracked:
423
445
  cmd.append('--untracked-files=all')
424
446
 
425
- results = git(cmd)
447
+ results = git(cmd, path=path)
426
448
 
427
449
  # Dictionary of results, indexed by filename where the status is 2 characters
428
450
  # the first representing the state of the file in the index and the second the state
@@ -491,39 +513,17 @@ def status(ignored=False, untracked=False, path=None):
491
513
 
492
514
  ################################################################################
493
515
 
494
- def working_tree(start_dir=None):
495
- """ Location of the current working tree or None if we are not in a working tree """
496
-
497
- repo_dir = git_dir(start_dir)
498
-
499
- if repo_dir:
500
- return os.path.abspath(os.path.join(repo_dir, os.pardir))
501
-
502
- return None
503
-
504
- ################################################################################
505
-
506
- def git_dir(start_dir=None):
507
- """ Return the relative path to the .git directory """
508
-
509
- if not start_dir:
510
- start_dir = os.getcwd()
511
-
512
- return pygit2.discover_repository(start_dir)
513
-
514
- ################################################################################
515
-
516
- def tree_path(filename):
516
+ def tree_path(filename, path=None):
517
517
  """ Normalise a filename (absolute or relative to the current directory)
518
518
  so that it is relative to the top-level directory of the working tree """
519
519
 
520
- git_tree = working_tree()
520
+ git_tree = working_tree(path=path)
521
521
 
522
522
  return os.path.relpath(filename, git_tree)
523
523
 
524
524
  ################################################################################
525
525
 
526
- def difftool(commit_1=None, commit_2=None, files=None, tool=None):
526
+ def difftool(commit_1=None, commit_2=None, files=None, tool=None, path=None):
527
527
  """ Run git difftool """
528
528
 
529
529
  cmd = ['difftool']
@@ -545,11 +545,11 @@ def difftool(commit_1=None, commit_2=None, files=None, tool=None):
545
545
  else:
546
546
  cmd += files
547
547
 
548
- return git(cmd)
548
+ return git(cmd, path=path)
549
549
 
550
550
  ################################################################################
551
551
 
552
- def commit_info(commit_1=None, commit_2=None, paths=None):
552
+ def commit_info(commit_1=None, commit_2=None, paths=None, path=None):
553
553
  """ Return details of changes either in single commit (defaulting to the most
554
554
  recent one) or between two commits, optionally restricted a path or paths
555
555
  """
@@ -572,7 +572,7 @@ def commit_info(commit_1=None, commit_2=None, paths=None):
572
572
  else:
573
573
  params += paths
574
574
 
575
- results = git(params)
575
+ results = git(params, path=path)
576
576
 
577
577
  # Parse the output
578
578
 
@@ -597,7 +597,7 @@ def commit_info(commit_1=None, commit_2=None, paths=None):
597
597
 
598
598
  ################################################################################
599
599
 
600
- def diff(commit=None, renames=True, copies=True, relative=False):
600
+ def diff(commit=None, renames=True, copies=True, relative=False, path=None):
601
601
  """ Return a list of differences between two commits, working tree and a commit or working tree and head """
602
602
 
603
603
  if commit:
@@ -623,17 +623,17 @@ def diff(commit=None, renames=True, copies=True, relative=False):
623
623
 
624
624
  cmd += commit
625
625
 
626
- return git(cmd)
626
+ return git(cmd, path=path)
627
627
 
628
628
  ################################################################################
629
629
 
630
- def diff_status(commit1, commit2='HEAD'):
630
+ def diff_status(commit1, commit2='HEAD', path=None):
631
631
  """ Return True if there is no difference between the two commits, False otherwise """
632
632
 
633
633
  cmd = ['diff', '--no-patch', '--exit-code', commit1, commit2]
634
634
 
635
635
  try:
636
- git(cmd)
636
+ git(cmd, path=path)
637
637
  except GitError:
638
638
  return False
639
639
 
@@ -641,24 +641,24 @@ def diff_status(commit1, commit2='HEAD'):
641
641
 
642
642
  ################################################################################
643
643
 
644
- def show(revision, filename, outfile=None):
644
+ def show(revision, filename, outfile=None, path=None):
645
645
  """ Return the output from git show revision:filename """
646
646
 
647
- return git(['show', f'{revision}:{filename}'], stdout=outfile)
647
+ return git(['show', f'{revision}:{filename}'], stdout=outfile, path=path)
648
648
 
649
649
  ################################################################################
650
650
 
651
- def add(files):
651
+ def add(files, path=None):
652
652
  """ Add file to git """
653
653
 
654
- return git(['add'] + files)
654
+ return git(['add'] + files, path=path)
655
655
 
656
656
  ################################################################################
657
657
 
658
- def rm(files):
658
+ def rm(files, path=None):
659
659
  """ Remove files from git """
660
660
 
661
- return git(['rm'] + files)
661
+ return git(['rm'] + files, path=path)
662
662
 
663
663
  ################################################################################
664
664
 
@@ -768,14 +768,14 @@ def push(all=False, mirror=False, tags=False, atomic=False, dry_run=False,
768
768
 
769
769
  ################################################################################
770
770
 
771
- def reset(sha1):
771
+ def reset(sha1, path=None):
772
772
  """ Run git reset """
773
773
 
774
- return git(['reset', sha1])
774
+ return git(['reset', sha1], path=path)
775
775
 
776
776
  ################################################################################
777
777
 
778
- def config_get(section, key, source=LOCAL, defaultvalue=None):
778
+ def config_get(section, key, source=LOCAL, defaultvalue=None, path=None):
779
779
  """ Return the specified configuration entry
780
780
  Returns a default value if no matching configuration entry exists """
781
781
 
@@ -789,13 +789,13 @@ def config_get(section, key, source=LOCAL, defaultvalue=None):
789
789
  cmd += ['--get', f'{section}.{key}']
790
790
 
791
791
  try:
792
- return git(cmd)[0]
792
+ return git(cmd, path=path)[0]
793
793
  except GitError:
794
794
  return defaultvalue
795
795
 
796
796
  ################################################################################
797
797
 
798
- def config_set(section, key, value, source=LOCAL):
798
+ def config_set(section, key, value, source=LOCAL, path=None):
799
799
  """ Set a configuration entry """
800
800
 
801
801
  cmd = ['config']
@@ -807,11 +807,11 @@ def config_set(section, key, value, source=LOCAL):
807
807
 
808
808
  cmd += ['--replace-all', f'{section}.{key}', value]
809
809
 
810
- return git(cmd)
810
+ return git(cmd, path=path)
811
811
 
812
812
  ################################################################################
813
813
 
814
- def config_rm(section, key, source=LOCAL):
814
+ def config_rm(section, key, source=LOCAL, path=None):
815
815
  """ Remove a configuration entry """
816
816
 
817
817
  cmd = ['config']
@@ -823,11 +823,11 @@ def config_rm(section, key, source=LOCAL):
823
823
 
824
824
  cmd += ['--unset', f'{section}.{key}']
825
825
 
826
- return git(cmd)
826
+ return git(cmd, path=path)
827
827
 
828
828
  ################################################################################
829
829
 
830
- def ref(fields=('objectname'), sort=None, remotes=False):
830
+ def ref(fields=('objectname'), sort=None, remotes=False, path=None):
831
831
  """ Wrapper for git for-each-ref """
832
832
 
833
833
  cmd = ['for-each-ref']
@@ -844,12 +844,12 @@ def ref(fields=('objectname'), sort=None, remotes=False):
844
844
  if remotes:
845
845
  cmd.append('refs/remotes/origin')
846
846
 
847
- for output in git(cmd):
847
+ for output in git(cmd, path=path):
848
848
  yield output.split('\0')
849
849
 
850
850
  ################################################################################
851
851
 
852
- def branches(all=False):
852
+ def branches(all=False, path=None):
853
853
  """ Return a list of all the branches in the current repo """
854
854
 
855
855
  cmd = ['branch']
@@ -858,7 +858,7 @@ def branches(all=False):
858
858
  cmd.append('--all')
859
859
 
860
860
  results = []
861
- for output in git(cmd):
861
+ for output in git(cmd, path=path):
862
862
  if ' -> ' not in output and '(HEAD detached at ' not in output:
863
863
  results.append(output[2:])
864
864
 
@@ -866,7 +866,7 @@ def branches(all=False):
866
866
 
867
867
  ################################################################################
868
868
 
869
- def delete_branch(branch, force=False, remote=False):
869
+ def delete_branch(branch, force=False, remote=False, path=None):
870
870
  """ Delete a branch, optionally forcefully and/or including the
871
871
  remote tracking branch """
872
872
 
@@ -880,11 +880,11 @@ def delete_branch(branch, force=False, remote=False):
880
880
 
881
881
  cmd.append(branch)
882
882
 
883
- return git(cmd)
883
+ return git(cmd, path=path)
884
884
 
885
885
  ################################################################################
886
886
 
887
- def remote_prune(remote, dry_run=False):
887
+ def remote_prune(remote, dry_run=False, path=None):
888
888
  """ Return a list of remote tracking branches that no longer exist on the
889
889
  specified remote """
890
890
 
@@ -893,7 +893,7 @@ def remote_prune(remote, dry_run=False):
893
893
  if dry_run:
894
894
  cmd.append('--dry-run')
895
895
 
896
- results = git(cmd)
896
+ results = git(cmd, path=path)
897
897
 
898
898
  prunable_branches = []
899
899
 
@@ -908,32 +908,32 @@ def remote_prune(remote, dry_run=False):
908
908
 
909
909
  ################################################################################
910
910
 
911
- def get_commits(commit1, commit2):
911
+ def get_commits(commit1, commit2, path=None):
912
912
  """ Get a list of commits separating two commits """
913
913
 
914
- return git(['rev-list', commit1, f'^{commit2}'])
914
+ return git(['rev-list', commit1, f'^{commit2}'], path=path)
915
915
 
916
916
  ################################################################################
917
917
 
918
- def commit_count(commit1, commit2):
918
+ def commit_count(commit1, commit2, path=None):
919
919
  """ Get a count of the number of commits between two commits """
920
920
 
921
- return int(git(['rev-list', '--count', commit1, '^%s' % commit2])[0])
921
+ return int(git(['rev-list', '--count', commit1, f'^{commit2}'], path=path)[0])
922
922
 
923
923
  ################################################################################
924
924
 
925
- def branch_name(branch):
925
+ def branch_name(branch, path=None):
926
926
  """ Return the full name of a branch given an abbreviation - e.g. @{upstream}
927
927
  for the upstream branch """
928
928
 
929
- return git(['rev-parse', '--abbrev-ref', '--symbolic-full-name', branch])[0]
929
+ return git(['rev-parse', '--abbrev-ref', '--symbolic-full-name', branch], path=path)[0]
930
930
 
931
931
  ################################################################################
932
932
 
933
- def author(commit):
933
+ def author(commit, path=None):
934
934
  """ Return the author of a commit """
935
935
 
936
- return git(['show', '--format=format:%an', commit])[0]
936
+ return git(['show', '--format=format:%an', commit], path=path)[0]
937
937
 
938
938
  ################################################################################
939
939
 
@@ -944,7 +944,7 @@ def commit_changes(commit='HEAD', path=None):
944
944
 
945
945
  ################################################################################
946
946
 
947
- def files(dir=None):
947
+ def files(dir=None, path=None):
948
948
  """ Return the output from 'git ls-files' """
949
949
 
950
950
  cmd = ['ls-files']
@@ -952,20 +952,20 @@ def files(dir=None):
952
952
  if dir:
953
953
  cmd.append(dir)
954
954
 
955
- return git(cmd)
955
+ return git(cmd, path=path)
956
956
 
957
957
  ################################################################################
958
958
 
959
- def stash():
959
+ def stash(path=None):
960
960
  """ Return the list of stashed items (if any) """
961
961
 
962
962
  cmd = ['stash', 'list']
963
963
 
964
- return git(cmd)
964
+ return git(cmd, path=path)
965
965
 
966
966
  ################################################################################
967
967
 
968
- def parents(commit=None, ignore=None):
968
+ def parents(commit=None, ignore=None, path=None):
969
969
  """ Look at the commits down the history of the specified branch,
970
970
  looking for another branch or branches that also contain the same commit.
971
971
  The first found is the parent (or equally-likely parents) of the
@@ -977,16 +977,16 @@ def parents(commit=None, ignore=None):
977
977
 
978
978
  # Get the history of the branch
979
979
 
980
- current_branch = commit or branch('HEAD')
980
+ current_branch = commit or branch('HEAD', path=path)
981
981
 
982
- current_history = git(['rev-list', current_branch])
982
+ current_history = git(['rev-list', current_branch], path=path)
983
983
 
984
984
  # Look down the commits on the current branch for other branches that have
985
985
  # the same commit, using the ignore pattern if there is one.
986
986
 
987
987
  for distance, ancestor in enumerate(current_history):
988
988
  branches = []
989
- for brnch in git(['branch', '--contains', ancestor]):
989
+ for brnch in git(['branch', '--contains', ancestor], path=path):
990
990
  brnch = brnch[2:]
991
991
  if brnch != current_branch and '(HEAD detached at' not in brnch:
992
992
  if not ignore or (ignore and not fnmatch.fnmatch(brnch, ignore)):
@@ -1001,13 +1001,11 @@ def parents(commit=None, ignore=None):
1001
1001
 
1002
1002
  ################################################################################
1003
1003
 
1004
- def find_common_ancestor(branch1='HEAD', branch2='master'):
1004
+ def find_common_ancestor(branch1='HEAD', branch2='master', path=None):
1005
1005
  """ Find the first (oldest) commit that the two branches have in common
1006
1006
  i.e. the point where one branch was forked from the other """
1007
1007
 
1008
- common = git(['merge-base', branch1, branch2])[0]
1009
-
1010
- return common
1008
+ return git(['merge-base', branch1, branch2], path=path)[0]
1011
1009
 
1012
1010
  ################################################################################
1013
1011
 
@@ -1058,7 +1056,7 @@ _GREP_NON_BOOL_OPTLIST = \
1058
1056
  ('parent_basename', '--parent-basename')
1059
1057
  )
1060
1058
 
1061
- def grep(pattern, git_dir=None, work_tree=None, options=None, wildcards=None):
1059
+ def grep(pattern, git_dir=None, work_tree=None, options=None, wildcards=None, path=None):
1062
1060
  """ Run git grep - takes a painfully large number of options passed
1063
1061
  as a dictionary. """
1064
1062
 
@@ -1095,23 +1093,23 @@ def grep(pattern, git_dir=None, work_tree=None, options=None, wildcards=None):
1095
1093
  cmd.append('--')
1096
1094
  cmd += wildcards
1097
1095
 
1098
- return git_run_status(cmd)
1096
+ return git_run_status(cmd, path=path)
1099
1097
 
1100
1098
  ################################################################################
1101
1099
 
1102
- def isbranch(branchname):
1100
+ def isbranch(branchname, path=None):
1103
1101
  """ Return true if the specified branch exists """
1104
1102
 
1105
- return branchname in branches(True)
1103
+ return branchname in branches(True, path=path)
1106
1104
 
1107
1105
  ################################################################################
1108
1106
 
1109
- def default_branch():
1107
+ def default_branch(path=None):
1110
1108
  """ Return the name of the default branch, attempting to interrogate GitLab
1111
1109
  if the repo appears to have been cloned from there and falling back to
1112
1110
  returning whichever one of 'develop', 'main' or 'master' exists. """
1113
1111
 
1114
- remote_list = remotes()
1112
+ remote_list = remotes(path=path)
1115
1113
  if remote_list:
1116
1114
  for name in remote_list:
1117
1115
  if 'gitlab' in remote_list[name]:
@@ -1119,7 +1117,7 @@ def default_branch():
1119
1117
  repo = remote_list[name].split(':')[1]
1120
1118
 
1121
1119
  if not url.startswith('http://') or not url.startswith('https://'):
1122
- url = 'https://%s' % url
1120
+ url = f'https://{url}'
1123
1121
 
1124
1122
  if repo.endswith('.git'):
1125
1123
  repo = repo[:-4]
@@ -1131,7 +1129,7 @@ def default_branch():
1131
1129
  except gitlab.GitLabError:
1132
1130
  return None
1133
1131
 
1134
- git_branches = branches()
1132
+ git_branches = branches(path=path)
1135
1133
 
1136
1134
  for branch in ('develop', 'main', 'master'):
1137
1135
  if branch in git_branches:
@@ -1141,7 +1139,7 @@ def default_branch():
1141
1139
 
1142
1140
  ################################################################################
1143
1141
 
1144
- def matching_branch(branchname, case=False):
1142
+ def matching_branch(branchname, case=False, path=None):
1145
1143
  """ Look for a branch matching the specified name and return it
1146
1144
  out if it is an exact match or there is only one partial
1147
1145
  match. If there are multiple branches that match, return them
@@ -1153,7 +1151,7 @@ def matching_branch(branchname, case=False):
1153
1151
  otherwise, it just checks for a branches containing the branchname
1154
1152
  as a substring. """
1155
1153
 
1156
- all_branches = branches(all=True)
1154
+ all_branches = branches(all=True, path=path)
1157
1155
 
1158
1156
  # Always return exact matches
1159
1157
 
@@ -1205,7 +1203,7 @@ def matching_branch(branchname, case=False):
1205
1203
 
1206
1204
  ################################################################################
1207
1205
 
1208
- def update(clean=False, all=False):
1206
+ def update(clean=False, all=False, path=None):
1209
1207
  """ Run git update (which is a thingy command, and may end up as a module
1210
1208
  but for the moment, we'll treat it as any other git command) """
1211
1209
 
@@ -1217,18 +1215,18 @@ def update(clean=False, all=False):
1217
1215
  if all:
1218
1216
  cmd.append('--all')
1219
1217
 
1220
- return git(cmd)
1218
+ return git(cmd, path=path)
1221
1219
 
1222
1220
  ################################################################################
1223
1221
 
1224
- def object_type(name):
1222
+ def object_type(name, path=None):
1225
1223
  """ Return the git object type (commit, tag, blob, ...) """
1226
1224
 
1227
- return git(['cat-file', '-t', name])[0]
1225
+ return git(['cat-file', '-t', name], path=path)[0]
1228
1226
 
1229
1227
  ################################################################################
1230
1228
 
1231
- def matching_commit(name):
1229
+ def matching_commit(name, path=None):
1232
1230
  """ Similar to matching_branch() (see above).
1233
1231
  If the name uniquely matches a branch, return that
1234
1232
  If it matches multiple branches return a list
@@ -1244,7 +1242,7 @@ def matching_commit(name):
1244
1242
 
1245
1243
  # Look for at least one matching branch
1246
1244
 
1247
- matches = matching_branch(name)
1245
+ matches = matching_branch(name, path=path)
1248
1246
 
1249
1247
  if matches:
1250
1248
  return matches
@@ -1262,7 +1260,7 @@ def matching_commit(name):
1262
1260
  # Look for a matching commit
1263
1261
 
1264
1262
  try:
1265
- commit_type = object_type(name)
1263
+ commit_type = object_type(name, path=path)
1266
1264
 
1267
1265
  if commit_type == 'commit':
1268
1266
  matches = [name]
@@ -1273,7 +1271,7 @@ def matching_commit(name):
1273
1271
 
1274
1272
  ################################################################################
1275
1273
 
1276
- def log(branch1, branch2=None):
1274
+ def log(branch1, branch2=None, path=None):
1277
1275
  """ Return the git log between the given commits """
1278
1276
 
1279
1277
  if branch2:
@@ -1281,7 +1279,7 @@ def log(branch1, branch2=None):
1281
1279
  else:
1282
1280
  cmd = ['log', '-n1', branch1]
1283
1281
 
1284
- return git(cmd)
1282
+ return git(cmd, path=path)
1285
1283
 
1286
1284
  ################################################################################
1287
1285
 
@@ -1354,7 +1352,7 @@ if __name__ == '__main__':
1354
1352
 
1355
1353
  print('')
1356
1354
 
1357
- with open('newfile.txt', 'w') as newfile:
1355
+ with open('newfile.txt', 'w', encoding='utf8') as newfile:
1358
1356
  newfile.write('THIS IS A TEST')
1359
1357
 
1360
1358
  print('Adding and committing "newfile.txt"')
@@ -1376,7 +1374,7 @@ if __name__ == '__main__':
1376
1374
  print('Commit info for HEAD %s' % commit_info('HEAD'))
1377
1375
 
1378
1376
  except GitError as exc:
1379
- sys.stderr.write('ERROR: %s' % exc.msg)
1377
+ sys.stderr.write(f'ERROR: {exc.msg}')
1380
1378
  sys.exit(1)
1381
1379
 
1382
1380
  finally: