Skip to content

Commit dd17dc1

Browse files
author
Mark Ruvald Pedersen
committed
args: Add -add-ignored to add files despite being in .gitignore
.gitignore usually contain temporary, generated/derived files - which we want to commit.
1 parent c0dbbbd commit dd17dc1

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/git_recycle_bin.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def parse_commit_msg(commit_msg):
209209

210210

211211

212-
def create_artifact_commit(rbgit, artifact_name: str, binpath: str, expire_branch: str) -> str:
212+
def create_artifact_commit(rbgit, artifact_name: str, binpath: str, expire_branch: str, add_ignored: bool) -> str:
213213
""" Create Artifact: A binary commit, with builtin traceability and expiry """
214214
if not os.path.exists(binpath):
215215
raise RuntimeError(f"Artifact '{binpath}' does not exist!")
@@ -276,7 +276,7 @@ def create_artifact_commit(rbgit, artifact_name: str, binpath: str, expire_branc
276276
rbgit.checkout_orphan_idempotent(d['bin_branch_name'])
277277

278278
printer.high_level(f"Adding '{binpath}' as '{d['artifact_relpath_nca']}' ...", file=sys.stderr)
279-
changes = rbgit.add(binpath)
279+
changes = rbgit.add(binpath, force=add_ignored)
280280
if changes == True:
281281
# Set {author,committer}-dates: Make our new commit reproducible by copying from the source; do not sample the current time.
282282
# Sampling the current time would lead to new commit SHA every time, thus not idempotent.
@@ -337,6 +337,7 @@ def __init__(self, prog):
337337
g = parser.add_argument_group('Niche arguments')
338338
g.add_argument("--user-name", metavar='fullname', required=False, type=str, default=os.getenv('GITRB_USERNAME'), help="Author of artifact commit. Defaults to yourself.")
339339
g.add_argument("--user-email", metavar='address', required=False, type=str, default=os.getenv('GITRB_EMAIL'), help="Author's email of artifact commit. Defaults to your own.")
340+
dv = 'False'; g.add_argument("--add-ignored", metavar='bool', type=str2bool, nargs='?', const=True, default=os.getenv('GITRB_ADD_IGNORED', dv), help=f"Add despite gitignore. Default {dv}.")
340341
dv = 'False'; g.add_argument("--force-branch", metavar='bool', type=str2bool, nargs='?', const=True, default=os.getenv('GITRB_FORCE_BRANCH', dv), help=f"Force push of branch. Default {dv}.")
341342
dv = 'False'; g.add_argument("--force-tag", metavar='bool', type=str2bool, nargs='?', const=True, default=os.getenv('GITRB_FORCE_TAG', dv), help=f"Force push of tag. Default {dv}.")
342343
dv = 'True'; g.add_argument("--rm-tmp", metavar='bool', type=str2bool, nargs='?', const=True, default=os.getenv('GITRB_RM_TMP', dv), help=f"Remove local bin-repo. Default {dv}.")
@@ -386,7 +387,7 @@ def __init__(self, prog):
386387
rbgit.cmd("config", "--local", "user.email", args.user_email)
387388

388389
printer.high_level(f"Making local commit of artifact {args.path} in artifact-repo at {rbgit.rbgit_dir}", file=sys.stderr)
389-
d = create_artifact_commit(rbgit, args.name, args.path, args.expire)
390+
d = create_artifact_commit(rbgit, args.name, args.path, args.expire, args.add_ignored)
390391
if d['bin_tag_name']:
391392
rbgit.set_tag(tag_name=d['bin_tag_name'], tag_val=d['bin_sha_commit'])
392393
printer.detail(rbgit.cmd("branch", "-vv"))

src/rbgit.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,13 @@ def checkout_orphan_idempotent(self, branch_name: str):
4848
# If the branch doesn't exist, create it as an orphan
4949
self.cmd("checkout", "--orphan", branch_name)
5050

51-
def add(self, binpath: str) -> bool:
51+
def add(self, binpath: str, force: bool = False) -> bool:
5252
# TODO: Check binpath exists
5353
changes = False
54-
self.cmd("add", binpath)
54+
if force:
55+
self.cmd("add", "--force", binpath)
56+
else:
57+
self.cmd("add", binpath)
5558

5659
try:
5760
# Check if there are any changes staged for the next commit

0 commit comments

Comments
 (0)