@@ -362,6 +362,7 @@ def unignore(dest):
362
362
@staticclass
363
363
class Hg (object ):
364
364
name = 'hg'
365
+ ignore_file = os .path .join ('.hg' , 'hgignore' )
365
366
366
367
def isurl (url ):
367
368
m_url = re .match (regex_url_ref , url .strip ().replace ('\\ ' , '/' ))
@@ -476,7 +477,7 @@ def getbranch():
476
477
def remoteid (url , rev = None ):
477
478
return pquery ([hg_cmd , 'id' , '--id' , url ] + (['-r' , rev ] if rev else [])).strip () or ""
478
479
479
- def ignores ():
480
+ def hgrc ():
480
481
hook = 'ignore.local = .hg/hgignore'
481
482
hgrc = os .path .join ('.hg' , 'hgrc' )
482
483
try :
@@ -493,68 +494,51 @@ def ignores():
493
494
except IOError :
494
495
error ("Unable to write hgrc file in \" %s\" " % hgrc , 1 )
495
496
496
- exclude = os .path .join ('.hg' , 'hgignore' )
497
+ def ignores ():
498
+ Hg .hgrc ()
497
499
try :
498
- with open (exclude , 'w' ) as f :
500
+ with open (Hg . ignore_file , 'w' ) as f :
499
501
f .write ("syntax: glob\n " + '\n ' .join (ignores )+ '\n ' )
500
502
except IOError :
501
- error ("Unable to write ignore file in \" %s\" " % exclude , 1 )
503
+ error ("Unable to write ignore file in \" %s\" " % os . path . join ( os . getcwd , Hg . ignore_file ) , 1 )
502
504
503
505
def ignore (dest ):
504
- hook = 'ignore.local = .hg/hgignore'
505
- hgrc = os .path .join ('.hg' , 'hgrc' )
506
+ Hg .hgrc ()
506
507
try :
507
- with open (hgrc ) as f :
508
- exists = hook in f .read ().splitlines ()
509
- except IOError :
510
- exists = False
511
-
512
- if not exists :
513
- try :
514
- with open (hgrc , 'a' ) as f :
515
- f .write ('[ui]\n ' )
516
- f .write (hook + '\n ' )
517
- except IOError :
518
- error ("Unable to write hgrc file in \" %s\" " % hgrc , 1 )
519
-
520
- exclude = os .path .join ('.hg' , 'hgignore' )
521
- try :
522
- with open (exclude ) as f :
508
+ with open (Hg .ignore_file ) as f :
523
509
exists = dest in f .read ().splitlines ()
524
510
except IOError :
525
511
exists = False
526
512
527
513
if not exists :
528
514
try :
529
- with open (exclude , 'a' ) as f :
515
+ with open (Hg . ignore_file , 'a' ) as f :
530
516
f .write (dest + '\n ' )
531
517
except IOError :
532
- error ("Unable to write ignore file in \" %s\" " % exclude , 1 )
518
+ error ("Unable to write ignore file in \" %s\" " % os . path . join ( os . getcwd , Hg . ignore_file ) , 1 )
533
519
534
520
def unignore (dest ):
535
- exclude = os .path .join ('.hg' , 'hgignore' )
521
+ Hg . ignore_file = os .path .join ('.hg' , 'hgignore' )
536
522
try :
537
- with open (exclude ) as f :
523
+ with open (Hg . ignore_file ) as f :
538
524
lines = f .read ().splitlines ()
539
- except :
525
+ except IOError :
540
526
lines = []
541
527
542
- if dest not in lines :
543
- return
544
-
545
- lines .remove (dest )
546
-
547
- try :
548
- with open (exclude , 'w' ) as f :
549
- f .write ('\n ' .join (lines ) + '\n ' )
550
- except IOError :
551
- error ("Unable to write ignore file in \" %s\" " % exclude , 1 )
528
+ if dest in lines :
529
+ lines .remove (dest )
530
+ try :
531
+ with open (Hg .ignore_file , 'w' ) as f :
532
+ f .write ('\n ' .join (lines ) + '\n ' )
533
+ except IOError :
534
+ error ("Unable to write ignore file in \" %s\" " % os .path .join (os .getcwd , Hg .ignore_file ), 1 )
552
535
553
536
# pylint: disable=no-self-argument, no-method-argument, no-member, no-self-use, unused-argument
554
537
@scm ('git' )
555
538
@staticclass
556
539
class Git (object ):
557
540
name = 'git'
541
+ ignore_file = os .path .join ('.git' , 'info' , 'exclude' )
558
542
559
543
def isurl (url ):
560
544
m_url = re .match (regex_url_ref , url .strip ().replace ('\\ ' , '/' ))
@@ -643,7 +627,7 @@ def update(repo, rev=None, clean=False):
643
627
if clean :
644
628
Git .discard (repo )
645
629
if not repo .is_local :
646
- Git .fetch (repo )
630
+ Git .fetch (repo )
647
631
if rev :
648
632
Git .checkout (repo , rev , clean )
649
633
else :
@@ -755,36 +739,39 @@ def revbranches(rev):
755
739
return branches
756
740
757
741
def ignores ():
758
- with open (os .path .join ('.git' , 'info' , 'exclude' ), 'w' ) as f :
759
- f .write ('\n ' .join (ignores )+ '\n ' )
742
+ try :
743
+ with open (Git .ignore_file , 'w' ) as f :
744
+ f .write ('\n ' .join (ignores )+ '\n ' )
745
+ except IOError :
746
+ error ("Unable to write ignore file in \" %s\" " % os .path .join (os .getcwd , Git .ignore_file ), 1 )
760
747
761
748
def ignore (dest ):
762
- exclude = os .path .join ('.git' , 'info' , 'exclude' )
763
749
try :
764
- with open (exclude ) as f :
750
+ with open (Git . ignore_file ) as f :
765
751
exists = dest in f .read ().splitlines ()
766
752
except IOError :
767
753
exists = False
768
754
769
755
if not exists :
770
- with open (exclude , 'a' ) as f :
771
- f .write (dest .replace ("\\ " , "/" ) + '\n ' )
772
-
756
+ try :
757
+ with open (Git .ignore_file , 'a' ) as f :
758
+ f .write (dest .replace ("\\ " , "/" ) + '\n ' )
759
+ except IOError :
760
+ error ("Unable to write ignore file in \" %s\" " % os .path .join (os .getcwd , Git .ignore_file ), 1 )
773
761
def unignore (dest ):
774
- exclude = os .path .join ('.git' , 'info' , 'exclude' )
775
762
try :
776
- with open (exclude ) as f :
763
+ with open (Git . ignore_file ) as f :
777
764
lines = f .read ().splitlines ()
778
- except :
765
+ except IOError :
779
766
lines = []
780
767
781
- if dest not in lines :
782
- return
783
- lines . remove ( dest )
784
-
785
- with open ( exclude , 'w' ) as f :
786
- f . write ( ' \n ' . join ( lines ) + ' \n ' )
787
-
768
+ if dest in lines :
769
+ lines . remove ( dest )
770
+ try :
771
+ with open ( Git . ignore_file , 'w' ) as f :
772
+ f . write ( ' \n ' . join ( lines ) + ' \n ' )
773
+ except IOError :
774
+ error ( "Unable to write ignore file in \" %s \" " % os . path . join ( os . getcwd , Git . ignore_file ), 1 )
788
775
789
776
# Repository object
790
777
class Repo (object ):
0 commit comments