25 Commits

Author SHA1 Message Date
e52e32a2c0 trying again 2022-10-21 02:22:04 +02:00
6a999ef25d removed win 2022-10-21 02:19:05 +02:00
7918006315 without man pages 2022-10-21 02:11:17 +02:00
61f4423d47 fix space 2022-10-21 02:05:27 +02:00
df2cae393c with license 2022-10-21 02:00:19 +02:00
0a0d05c048 Added homebrew 2022-10-21 01:50:06 +02:00
807611ffce With executable rights 2022-10-21 01:47:18 +02:00
def18273f4 ... 2022-10-21 01:42:18 +02:00
0391ec2b69 Add testing branch 2022-10-21 01:41:30 +02:00
564c76c38b added releaser 2022-10-21 01:39:22 +02:00
054c165954 added brew formula 2022-10-21 01:27:57 +02:00
7fed0deb28 add post install 2022-10-21 01:10:15 +02:00
372e85cc7f bump version 2022-10-21 01:05:14 +02:00
27cadd2607 updated readme 2022-10-21 01:04:45 +02:00
f5f4caeb1f with updated name 2022-10-21 01:03:53 +02:00
f89492f79e with actual category 2022-10-21 01:00:09 +02:00
9458211728 move readme 2022-10-21 00:56:13 +02:00
6b71e355aa add inner package 2022-10-21 00:55:29 +02:00
c53f91e840 Fixed publish 2022-10-21 00:45:57 +02:00
63cb562ac1 removed duplicates 2022-10-21 00:28:58 +02:00
acac0fe944 add install instructions 2022-10-21 00:26:35 +02:00
e13479c190 Add readme 2022-10-21 00:25:14 +02:00
09cd5a7e31 Added scripts for installing command 2022-10-21 00:23:12 +02:00
b939593445 it wooorks 2022-10-21 00:11:12 +02:00
a03c1706d1 Add git rm cached 2022-10-21 00:07:44 +02:00
17 changed files with 376 additions and 25 deletions

177
.github/workflows/release.yml vendored Normal file
View File

@@ -0,0 +1,177 @@
# The way this works is the following:
#
# The create-release job runs purely to initialize the GitHub release itself
# and to output upload_url for the following job.
#
# The build-release job runs only once create-release is finished. It gets the
# release upload URL from create-release job outputs, then builds the release
# executables for each supported platform and attaches them as release assets
# to the previously created release.
#
# The key here is that we create the release only once.
#
# Reference:
# https://eugene-babichenko.github.io/blog/2020/05/09/github-actions-cross-platform-auto-releases/
name: release
on:
push:
# Enable when testing release infrastructure on a branch.
branches:
- kjuulh/test
tags:
- "[0-9]+.[0-9]+.[0-9]+"
jobs:
create-release:
name: create-release
runs-on: ubuntu-22.04
# env:
# Set to force version number, e.g., when no tag exists.
# KIGNORE_VERSION: TEST-0.0.0
outputs:
upload_url: ${{ steps.release.outputs.upload_url }}
kignore_version: ${{ env.KIGNORE_VERSION }}
steps:
- name: Get the release version from the tag
shell: bash
if: env.KIGNORE_VERSION == ''
run: |
# Apparently, this is the right way to get a tag name. Really?
#
# See: https://github.community/t5/GitHub-Actions/How-to-get-just-the-tag-name/m-p/32167/highlight/true#M1027
echo "KIGNORE_VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
echo "version is: ${{ env.KIGNORE_VERSION }}"
- name: Create GitHub release
id: release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.KIGNORE_VERSION }}
release_name: ${{ env.KIGNORE_VERSION }}
build-release:
name: build-release
needs: ["create-release"]
runs-on: ${{ matrix.os }}
env:
# For some builds, we use cross to test on 32-bit and big-endian
# systems.
CARGO: cargo
# When CARGO is set to CROSS, this is set to `--target matrix.target`.
TARGET_FLAGS: ""
# When CARGO is set to CROSS, TARGET_DIR includes matrix.target.
TARGET_DIR: ./target
# Emit backtraces on panics.
RUST_BACKTRACE: 1
# Build static releases with PCRE2.
PCRE2_SYS_STATIC: 1
strategy:
matrix:
build: [linux, linux-arm, macos] #, win-msvc, win-gnu, win32-msvc]
include:
- build: linux
os: ubuntu-22.04
rust: nightly
target: x86_64-unknown-linux-musl
- build: linux-arm
os: ubuntu-22.04
rust: nightly
target: arm-unknown-linux-gnueabihf
- build: macos
os: macos-12
rust: nightly
target:
x86_64-apple-darwin
# - build: win-msvc
# os: windows-2022
# rust: nightly
# target: x86_64-pc-windows-msvc
# - build: win-gnu
# os: windows-2022
# rust: nightly-x86_64-gnu
# target: x86_64-pc-windows-gnu
# - build: win32-msvc
# os: windows-2022
# rust: nightly
# target: i686-pc-windows-msvc
steps:
- name: Checkout repository
uses:
actions/checkout@v3
#- name: Install packages (Ubuntu)
# if: matrix.os == 'ubuntu-22.04'
# run: |
# ci/ubuntu-install-packages
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
target: ${{ matrix.target }}
- name: Use Cross
shell: bash
run: |
cargo install cross
echo "CARGO=cross" >> $GITHUB_ENV
echo "TARGET_FLAGS=--target ${{ matrix.target }}" >> $GITHUB_ENV
echo "TARGET_DIR=./target/${{ matrix.target }}" >> $GITHUB_ENV
- name: Show command used for Cargo
run: |
echo "cargo command is: ${{ env.CARGO }}"
echo "target flag is: ${{ env.TARGET_FLAGS }}"
echo "target dir is: ${{ env.TARGET_DIR }}"
- name: Build release binary
run: ${{ env.CARGO }} build --verbose --release ${{ env.TARGET_FLAGS }}
- name: Strip release binary (linux and macos)
if: matrix.build == 'linux' || matrix.build == 'macos'
run: strip "target/${{ matrix.target }}/release/kignore"
- name: Strip release binary (arm)
if: matrix.build == 'linux-arm'
run: |
docker run --rm -v \
"$PWD/target:/target:Z" \
rustembedded/cross:arm-unknown-linux-gnueabihf \
arm-linux-gnueabihf-strip \
/target/arm-unknown-linux-gnueabihf/release/kignore
- name: Build archive
shell: bash
run: |
outdir="$(ci/cargo-out-dir "${{ env.TARGET_DIR }}")"
staging="kignore-${{ needs.create-release.outputs.kignore_version }}-${{ matrix.target }}"
mkdir -p "$staging"/{complete,doc}
cp {README.md,LICENSE-MIT} "$staging/"
#cp {CHANGELOG.md,FAQ.md,GUIDE.md} "$staging/doc/"
#cp "$outdir"/{rg.bash,rg.fish,_rg.ps1} "$staging/complete/"
#cp complete/_rg "$staging/complete/"
if [ "${{ matrix.os }}" = "windows-2022" ]; then
cp "target/${{ matrix.target }}/release/kignore.exe" "$staging/"
7z a "$staging.zip" "$staging"
echo "ASSET=$staging.zip" >> $GITHUB_ENV
else
# The man page is only generated on Unix systems.
#cp "$outdir"/kignore.1 "$staging/doc/"
cp "target/${{ matrix.target }}/release/kignore" "$staging/"
tar czf "$staging.tar.gz" "$staging"
echo "ASSET=$staging.tar.gz" >> $GITHUB_ENV
fi
- name: Upload release archive
uses: actions/upload-release-asset@v1.0.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create-release.outputs.upload_url }}
asset_path: ${{ env.ASSET }}
asset_name: ${{ env.ASSET }}
asset_content_type: application/octet-stream

1
.gitignore vendored
View File

@@ -1,2 +1 @@
something/
target/

8
Cargo.lock generated
View File

@@ -82,6 +82,14 @@ dependencies = [
[[package]]
name = "gitignore"
version = "0.1.0"
dependencies = [
"eyre",
"gitignore_inner",
]
[[package]]
name = "gitignore_inner"
version = "0.1.0"
dependencies = [
"clap",
"console",

View File

@@ -1,4 +1,23 @@
[package]
name = "kignore"
version = "0.1.1"
authors = ["Kasper J. Hermansen <contact@kjuulh.io>"]
license = "MIT"
readme = "README.md"
keywords = ["git", "ignore", "clap", "interactive"]
repository = "https://github.com/kjuulh/gitignore"
documentation = "https://docs.rs/gitignore"
description = """
kignore is a tool for easily adding patterns to .gitignore and cleaning up afterwards
"""
categories = ["command-line-interface"]
edition = "2021"
[workspace]
members = [
"crates/gitignore"
"crates/gitignore_inner"
]
[dependencies]
eyre = "0.6.8"
gitignore_inner = {path = "crates/gitignore_inner", version = "0.1.0"}

1
HomebrewFormula Symbolic link
View File

@@ -0,0 +1 @@
pkg/brew/

7
LICENSE-MIT Normal file
View File

@@ -0,0 +1,7 @@
Copyright 2022 Kasper Juul Hermansen
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -1,4 +1,4 @@
# Git ignore
# Git ignore (kignore)
Is an extension for easily adding ignored files to `.gitignore files`, when
added it will by default also try to remove any files matching the pattern added
@@ -6,11 +6,42 @@ to .gitignore, this is by default also run in interactive mode, giving you the
option to confirm or deny
```bash
$ git ignore 'node_modules/'
$ kignore 'node_modules/'
found .gitignore .../some-path/.gitignore
Added node_modules/ to .gitignore
Searching env for pattern...
found:
<gitroot>/client/node_modules
? Remove from git state? (Y)es/(N)o/(C)ontinue/(A)bort
Removed node_modules/ from git index
```
```bash
$ git ignore 'node_modules/'
found .gitignore .../some-path/.gitignore
Added node_modules/ to .gitignore
Removed node_modules/ from git index
```
## Installation
### Cargo
Cargo will only pull the `kignore` command and won't add a subcommand to `git.
```bash
$ cargo install kignore
```
#### Post install
To get the `git ignore` subcommand working you will need to have the file
git-ignore available on your path, either add it yourself using
`git-alias/git-ignore` as a template or:
```
git clone https://github.com/kjuulh/gitignore
./scripts/install-git-alias.sh # only tested on mac and linux
```
### Homebrew
Added in HomebrewFormula
Instructions TBA

33
ci/build-dep Executable file
View File

@@ -0,0 +1,33 @@
#!/bin/bash
set -e
D="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
# This script builds a binary dpkg for Debian based distros. It does not
# currently run in CI, and is instead run manually and the resulting dpkg is
# uploaded to GitHub via the web UI.
#
# Note that this requires 'cargo deb', which can be installed with
# 'cargo install cargo-deb'.
#
# This should be run from the root of the ripgrep repo.
if ! command -V cargo-deb > /dev/null 2>&1; then
echo "cargo-deb command missing" >&2
exit 1
fi
# 'cargo deb' does not seem to provide a way to specify an asset that is
# created at build time, such as ripgrep's man page. To work around this,
# we force a debug build, copy out the man page (and shell completions)
# produced from that build, put it into a predictable location and then build
# the deb, which knows where to look.
cargo build
DEPLOY_DIR=deployment/deb
OUT_DIR="$("$D"/cargo-out-dir target/debug/)"
mkdir -p "$DEPLOY_DIR"
# Since we're distributing the dpkg, we don't know whether the user will have
# PCRE2 installed, so just do a static build.
PCRE2_SYS_STATIC=1 cargo deb --target x86_64-unknown-linux-musl

14
ci/cargo-out-dir Executable file
View File

@@ -0,0 +1,14 @@
#!/bin/bash
if [ $# != 1 ]; then
echo "Usage: $(basename "$0") <target-dir>" >&2
exit 2
fi
# This works by finding the most recent stamp file, which is produced by
# every ripgrep build.
target_dir="$1"
find "$target_dir" -name kignore-stamp -print0 \
| xargs -0 ls -t \
| head -n1 \
| xargs dirname

10
ci/ubuntu-install-packages Executable file
View File

@@ -0,0 +1,10 @@
#!/bin/sh
if ! command -V sudo; then
apt-get update
apt-get install -y --no-install-recommends sudo
fi
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
zsh xz-utils liblz4-tool musl-tools \
brotli zstd

View File

@@ -1,7 +1,17 @@
[package]
name = "gitignore"
name = "gitignore_inner"
version = "0.1.0"
edition = "2021"
authors = ["Kasper J. Hermansen <contact@kjuulh.io>"]
license = "MIT"
readme = "../../README.md"
keywords = ["git", "ignore", "clap", "interactive"]
repository = "https://github.com/kjuulh/gitignore"
documentation = "https://docs.rs/gitignore"
description = """
gitignore_inner is the internal module for cargo
"""
categories = ["command-line-interface"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@@ -5,7 +5,7 @@ use std::{env::current_dir, io::Read, path::PathBuf};
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
fn main() -> eyre::Result<()> {
pub fn main() -> eyre::Result<()> {
let matches = Command::new("gitignore")
.version("0.1")
.author("Kasper J. Hermansen <contact@kjuulh.io>")
@@ -50,13 +50,8 @@ Easily add patterns using `git ignore <pattern>` this will by default also help
}
enum GitActions {
AddPattern {
git_path: PathBuf,
gitignore_path: PathBuf,
},
CreateIgnoreAndAddPattern {
git_path: PathBuf,
},
AddPattern { gitignore_path: PathBuf },
CreateIgnoreAndAddPattern { git_path: PathBuf },
}
fn add_gitignore_pattern(term: console::Term, pattern: &String) -> eyre::Result<()> {
@@ -67,8 +62,7 @@ fn add_gitignore_pattern(term: console::Term, pattern: &String) -> eyre::Result<
let actions = match search_for_dotgitignore(&curdir)? {
// If we have an ignore path, make sure it is in a git repo as well
GitSearchResult::GitIgnore(ignorepath) => match search_for_git_root(&curdir)? {
GitSearchResult::Git(gitpath) => GitActions::AddPattern {
git_path: gitpath,
GitSearchResult::Git(_gitpath) => GitActions::AddPattern {
gitignore_path: ignorepath,
},
_ => return Err(eyre::anyhow!("could not find parent git directory")),
@@ -80,10 +74,7 @@ fn add_gitignore_pattern(term: console::Term, pattern: &String) -> eyre::Result<
};
match actions {
GitActions::AddPattern {
git_path,
gitignore_path,
} => {
GitActions::AddPattern { gitignore_path } => {
term.write_line("Found existing .gitignore")?;
let mut gitignore_file = open_gitignore_file(&gitignore_path)?;
let mut gitignore_content = String::new();
@@ -117,7 +108,26 @@ fn add_gitignore_pattern(term: console::Term, pattern: &String) -> eyre::Result<
}
}
// TODO: Run git rm -r --cached on the .git root
// TODO: Run git rm -r --cached --pathspec <pattern> on the .git root
let output = std::process::Command::new("git")
.arg("rm")
.arg("-r")
.arg("--cached")
.arg("--ignore-unmatch")
.arg(pattern)
.output()
.context("could not process git remove from index command")?;
String::from_utf8(output.stdout)?
.lines()
.chain(String::from_utf8(output.stderr)?.lines())
.try_for_each(|l| term.write_line(l))
.context("could not print all output to terminal")?;
if !output.status.success() {
return Err(eyre::anyhow!("failed to run git index command"));
}
term.write_line("git successfully removed files")?;
Ok(())
}

5
git-alias/git-ignore Executable file
View File

@@ -0,0 +1,5 @@
#!/usr/bin/env sh
set -e
gitignore $@

16
pkg/brew/kignore-bin.rb Normal file
View File

@@ -0,0 +1,16 @@
class Kignore < Formula
desc "Easily add items to .gitignore and cleanup afterwards"
homepage "https://github.com/kjuulh/gitignore"
version '0.1.1'
license "MIT"
if OS.mac?
url "https://github.com/kjuulh/kignore/releases/download/#{version}/kignore-#{version}-x86_64-apple-darwin.tar.gz"
sha256 ""
end
def install
bin.install "kignore"
end
end

8
scripts/install-git-alias.sh Executable file
View File

@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -e
mkdir ~/.git-bins
cp git-alias/git-ignore ~/.git-bins/git-ignore
echo "Make sure to add ~/.git-bins to your PATH"

3
src/main.rs Normal file
View File

@@ -0,0 +1,3 @@
fn main() -> eyre::Result<()> {
gitignore_inner::main()
}